data=[];
r=[1,2,3,4,5,6,7,8,9];
data.push(r.splice(7,1));
At the end I don't need the 8,9, I need
data=[1,2,3,4,5,6,7]
data=[];
r=[1,2,3,4,5,6,7,8,9];
data.push(r.splice(7,1));
At the end I don't need the 8,9, I need
data=[1,2,3,4,5,6,7]
You can just shallow copy with slice:
r = [1,2,3,4,5,6,7,8,9]
data = r.slice(0,-2)
Example:
var r = [1,2,3,4,5,6,7,8,9];
var data = r.slice(0,-2);
console.log(data);
Use slice
var r = [1, 2, 3, 4, 5, 6, 7, 8, 9];
let data = r.slice(0, 7);
console.log(data)
You can try like this way also, with r.length - 2
it just shorten your array
length
by 2 so here it is discarding last two elements.
r = [1, 2, 3, 4, 5, 6, 7, 8, 9];
r.length = r.length - 2;
console.log(r);