how to add an item to the beginning of the list?



how to add an item to the beginning of the list?..

Answer / Kapil Agari

To add an item to the beginning of a JavaScript array, you can use the unshift() method. The unshift() method adds one or more elements to the front of the array and returns the new length of the array.nnExample:n```javascriptnlet arr = [1, 2, 3];narr.unshift(0);nconsole.log(arr); // [0, 1, 2, 3]```

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Data Structures Interview Questions

How does a heap sort work?

1 Answers  


What are vectors used for in real life?

1 Answers  


What do you mean by general trees?

1 Answers  


What is the difference between Array and Array List ? Explain in brief with example.

1 Answers   MCN Solutions,


Explain implementation of traversal of a binary tree.

1 Answers  


Define threaded binary tree. Explain its common uses

1 Answers  


What is meant by hashing?

1 Answers  


What is the best case time complexity of bubble sort?

1 Answers  


What is bubble insertion selection sort?

1 Answers  


What is the difference between collections class vs collections interface?

1 Answers  


input function and output function in c language

2 Answers   TCS,


What is a postfix expression?

1 Answers  


Categories