User FAQs

If you have a question, please send it to us.


1) Can you describe an 'Array' ?
All arrays are zero-based by default.

let var1 = []; 
console.log( Array.isArray(var1) ); // added ES 2009

2) How would you return the size of a 1 dimensional array ?
This array is a zero based array.
You can use the length property to return the size of an array.
The length is one more than the highest index

var a = ['dog', 'cat', 'hen'];  
var b = new Array();
b[0] = 'dog';
b[1] = 'cat';
b[2] = 'hen';
b.length; // 3

3) Can you describe the 'push' and 'pop' methods ?
push - appends an item to the end of an existing array
pop - takes an item from the end of the an existing array


4) Can you describe the 'shift' and 'unshift' methods ?
shift - appends an item to the beginning of an existing array
unshift - takes an item from the beginning of an existing array


5) Can you list some Array methods ?



6) Can you list some Array properties ?



7) What is the best way to empty an array ?

var myArray = ['one, 'two','three','four']; 
myArray = []; // ignores any reference variables
myArray.length = 0; // includes reference variables
myArray.splice(0), myArray.length); // includes reference variables

8) Write a For loop to display all the values in an array ?

let myArray = ['one', 'two', 'three'];  
for (let item in myArray){
   console.log( myArray[item] );
}

for (var i = 0; i < myArray.length; i++) {
  console.log( myArray[i] );
}

// forEach method was added in ES 2015
myArray.forEach(function(currentValue, index, array) {
  console.log( currentValue );
});

9) Can you give an example of using 'Array.from' method ?
This method lets you create arrays from arrays-like objects or iterable objects.

Array.from( { length : N } , (v, i) => I ); 

10) Is it possible to start an array at index position 1 (instead of 0) ?
Yes. You can use the Map object (ES 2015) to store key-value pairs

var myArray = new Map( [[1,'one'], [2,'two']] ); 
console.log( myArray.get(2) );


© 2023 Better Solutions Limited. All Rights Reserved. © 2023 Better Solutions Limited TopPrevNext