javascript - How to store number of object element of array in another array? -
javascript - How to store number of object element of array in another array? -
im trying store object element 1 array lets have array of objects
var array = [{name:'fadi'},{name:'joseph'},{name:'salim'},{name:'tony'}];
and want store first 2 object in array array
var subarray =[{name:'fadi'},{name:'joseph'}];
thanks in advance help.
you can utilize slice
method this:
var subarray = array.slice(0,2);
please note array
reserved js global object. need utilize different name variable. code should example:
var myarray = [{name:'fadi'},{name:'joseph'},{name:'salim'},{name:'tony'}]; var subarray = myarray.slice(0,2);
javascript
Comments
Post a Comment