How do you append a value to an array of Java Script?
A. arr[arr.length+1] = new Arrays()
B. arr[arr.length*1] = value
C. arr[arr.length] = value
D. arr[arr.length-1] = value
Answers
Answered by
0
arr[arrlength ] =value
Answered by
1
Answer:
c
Explanation:
example:
if arr = [1, 2, 3, 4]
// Array Index is zero based. That is:
// 1 has index of 0; 2, index of 1; 3, index of 2; 4 index of 3
// The size or length of an array is the number of elements in it ([ ])
// The array, arr has length of 4, and the last index which is 3
// Therefore length = index + 1; or index = length - 1
// The next index after 4, is 4 and length of 5
// The appended element has: arr.index = arr.(length - 1 + 1) = arr.length
// Answer is C arr[index] = arr[arr.length] = value; length = 4;
// if appended value is 5. new array is: arr = [1, 2, 3, 4, 5]
// arr.length = 4, arr[arr.length] = arr[4] = 5
Similar questions