Linked Questions

424 votes
14 answers
462k views

var arr = [1,2,3,5,6]; Remove the first element I want to remove the first element of the array so that it becomes: var arr = [2,3,5,6]; Remove the second element To extend this question, what if I ...
user198729's user avatar
278 votes
10 answers
163k views

I am confused between the difference between the two function indexOf and find Index in an array. The documentation says findIndex - Returns the index of the first element in the array where ...
Rahul Singh's user avatar
  • 19.7k
24 votes
3 answers
19k views

I came across the following code: var f = function () { var args = Array.prototype.slice.call(arguments).splice(1); // some more code }; Basically, the result in args is an array that is a ...
Andreas Grech's user avatar
5 votes
5 answers
6k views

I want to extract last n elements from array without splice I have array like below , I want to get last 2 or n elements from any array in new array [33, 44] [22, 55, 77, 88, 99, 22, 33, 44] I ...
Gracie williams's user avatar
3 votes
5 answers
2k views

Is there any way to make the splice() non-destructive? What I need to do is to retain the arr2 as it is after I call the function. function foo(arr1, arr2, n) { let result = arr2; result....
isemaj's user avatar
  • 597
0 votes
2 answers
4k views

I am trying to copy an array to a new variable and then modify the array. Code: var test = [ { test: "test1", arr: ["1", "2", "3"] }, { test: "test2", arr: ["4", "5", "6"] ...
Prog_CS's user avatar
  • 33
0 votes
1 answer
2k views

function filter_list(l) { for (var i = 0; i < l.length; i++) { if (typeof(l[i]) === 'string') { l.splice(i, 1); } } return l; } console.log(filter_list([1, 2, 'a', 'b']))...
Smrithi Srinivaasan's user avatar
2 votes
1 answer
2k views

I'm trying to create my own pagination (without using a package), but I can't get it to work. I'm wondering if it has something to do with how I'm copying my arrays, but I'm not really sure. class ...
Annah Isenberg's user avatar
0 votes
3 answers
605 views

I am getting this typeError with split when I try to run this js. I am unsure of how to fix it, I defined it properly as shown in my textbook. var current; var string; console.log("Enter words ...
slowbro46's user avatar
1 vote
3 answers
163 views

I have an array with elements. for ex - let data = [ 1, 2, 3, 4, 5 ]; Now if I pass 2 in function as a parameter, then the last two value will move to first in the array. let data = [1, 2, 3, 4, 5];...
Sai's user avatar
  • 53
0 votes
1 answer
156 views

I've got the a list of objects iterating in object.keys, however how can I iterate between two numbers only(3-5)? And ignoring the rest of the list. const obj = { '#1 List title': [{ ...
Mint Con Design's user avatar
0 votes
1 answer
64 views

In my JavaScript code, I have a line of code that looks like this: const newArray = oldArray.splice(0); My question is what happens when there are concurrent modifications to oldArray during the ...
Anthony Luo's user avatar
-1 votes
2 answers
47 views

I know i can remove last item from array and first but I need to remove specified item based value Here is my array arrayItems: { volume: number; title: string; }[]; this.arrayItems = [{ ...
Miomir Dancevic's user avatar