1

How could I insert an array of items into an existing array if the start index is outside the bounds of the array I'm inserting.

For example:

[ 1, 2, 3 ]

I need to insert at index 10. I tried something like this:

Array.prototype.splice.apply(curData, [newData[0].index, 0].concat(newData));

but it respected the array bounds. This COULD be accomplished with a for loop but i'd say it wouldn't be very performant at all. Any ideas?

2
  • Why do you need to do this? What's the real world use case? Commented Aug 1, 2014 at 18:37
  • Table row virtualization when I only have partials results. Commented Aug 1, 2014 at 18:41

1 Answer 1

2
arrOne = [1, 2, 3];

arrTwo = [10, 11, 12, 13];

arrOne[9] = undefined;

arrOne.concat(arrTwo);
Sign up to request clarification or add additional context in comments.

1 Comment

Might want to use undefined instead.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.