Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
133
rated 0 times [  136] [ 3]  / answers: 1 / hits: 28560  / 8 Years ago, tue, september 20, 2016, 12:00:00

I have this array of objects and i would like to delete the last object. i.e. 2 from the list. Can someone please let me know to do this.



Object {Results:Array[3]}
Results:Array[3]
[0-2]
0:Object
id=1
name: Rick
Value: 34343
1:Object
id=2
name:'david'
Value: 2332
2:Object
id=3
name: 'Rio'
Value: 2333

More From » arrays

 Answers
3

You could just splice out the last element in the array:



obj.Results.splice(-1);




var obj = {
Results: [{
id: 1,
name: Rick,
Value: 34343
}, {
id:2,
name: 'david',
Value: 2332,
}, {
id: 3,
name: 'Rio',
Value: 2333
}]
};

obj.Results.splice(-1);
console.log(obj);




[#60660] Saturday, September 17, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
aidanl

Total Points: 156
Total Questions: 102
Total Answers: 112

Location: Saint Lucia
Member since Wed, Feb 8, 2023
1 Year ago
;