3

I have an array and when I am retriving my array I am getting something like this.

arr[0] = <li data="Dummy1" class= "Dummy1"></li>
arr[1] = <li data="Dummy2" class= "Dummy2"></li>
arr[2] = <li data="Dummy3" class= "Dummy3"></li>

Now after arr[0] I wanted to insert a div with style of cursor

<div style: 'cursor:auto'></div>

so my array will be look like

arr[0] = <li data="Dummy1" class= "Dummy1"></li>
arr[1] = <div style: 'cursor:auto'></div>
arr[2] = <li data="Dummy2" class= "Dummy2"></li>
arr[3] = <li data="Dummy3" class= "Dummy3"></li>

Can anybody help me how to achive this'

2 Answers 2

3

you can use this way the splice function on the array object:

arr.splice(1, 0, "<div style: 'cursor:auto'></div>");

This will insert the item in index 1 deleting 0 items.

Sign up to request clarification or add additional context in comments.

Comments

1

Use Array.splice() method : It will changes the contents of an array by removing existing elements and/or adding new elements.

var arr = [];

arr[0] = '<li data="Dummy1" class= "Dummy1"></li>';
arr[1] = '<li data="Dummy2" class= "Dummy2"></li>';
arr[2] = '<li data="Dummy3" class= "Dummy3"></li>';

arr.splice(1, 0, "<div style: 'cursor:auto'></div>");

console.log(arr);

Comments

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.