Created
March 25, 2015 21:32
-
-
Save Ridhwana/72aa2f74cf4751c41609 to your computer and use it in GitHub Desktop.
splice an array to add an item between every second row
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
var originalarray = ["row1", "row2", "row3", "row4", "row5", "row6", "row7", "row8"]; | |
var proxyarray = ["row1", "row2", "row3", "row4", "row5", "row6", "row7", "row8"]; | |
var i=0; | |
var founded=0; | |
while(i<=originalarray.length){ | |
if(i%2===0 && i>1){ | |
item= originalarray[i-2] + originalarray[i-1]; | |
proxyarray.splice(founded, 0, item); | |
founded ++; | |
} | |
i++; | |
founded++; | |
} | |
console.log(proxyarray); | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">var originalarray = ["row1", "row2", "row3", "row4", "row5", "row6", "row7", "row8"]; | |
var proxyarray = ["row1", "row2", "row3", "row4", "row5", "row6", "row7", "row8"]; | |
var i=0; | |
var founded=0; | |
while(i<=originalarray.length){ | |
if(i%2===0 && i>1){ | |
item= originalarray[i-2] + originalarray[i-1]; | |
proxyarray.splice(founded, 0, item); | |
founded ++; | |
} | |
i++; | |
founded++; | |
} | |
console.log(proxyarray);</script></body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment