If the array is sparse, the value of the length property is greater than the number of elements.
Exโ
var arr = [undefined ร 5, 1, 2, 3];
arr.length;
Ansโ 4
Q: In javascript, arrays are sparse.
Ans:yes
Q:In javascript, the length property always tells us how many elements are there in an array.
var arr = [undefined ร 5, 1, 2, 3, undefined ร 2]
arr.length;
in browser console:
arr = [undefine, undefine, undefine, undefine, undefine, 1,2,3, undefine, undefine];
Ans: no
because length of arr is 10 but element in the array is 3 that is 1,2,3
Q: If an array evaluates to [undefined ร 5, 1, 2, 3, undefined ร 2], it's length property will have a value of?
Ans: 10
arr = [undefined ร 5, 1, 2, 3, undefined ร 2];
arr.length;
10
Q: Given an array var x = [20, 30, 40, 50, 60];. If we want the array to be [10, 20, 30, 40, 50, 60, 70], which set of operations should be used?
Ans=> x.unshift(10); x.push(70);
Q: Consider the following code:
var x = [10,20,30,40,50];
x.unshift(60);
x.pop(50);
x.push(70);
The array x now looks like
Ans:โ- [60,10,20,30,40,70]