fr

Test Question Javascript

Write a Javascript code that prints the indexes of an array.

Hard

What will the following code display?

var names = ['Lea', 'John', 'Rachel', 'Yehuda'];
(function(){
    for(name in names){
        console.log(name);
    }
})();
Author: Jean-marie CléryStatus : PublishedQuestion answered 1,560 times
6
Reviews from developers
developer avatar
Anonymous author
04/06/2023
🇺🇸
The code will display the index numbers of each element in the names array, as name represents the index and not the element itself. Therefore, the output will be: 0123
⚠️
Your browser is badly|not supported!
We recommend you to use a more modern browser such as Edge, Chrome or Firefox
Know More