Try using the .pop() method. It'll delete the last item of an array.
obj.Results.pop();
Answer from Robiseb on Stack OverflowTry using the .pop() method. It'll delete the last item of an array.
obj.Results.pop();
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);
Array.prototype.pop() by JavaScript convention.
let fruit = ['apple', 'orange', 'banana', 'tomato'];
let popped = fruit.pop();
console.log(popped); // "tomato"
console.log(fruit); // ["apple", "orange", "banana"]
Run code snippetEdit code snippet Hide Results Copy to answer Expand
Use splice(startPosition, deleteCount)
array.splice(-1)
Show code snippet
var array = ['abc','def','ghi','123'];
var removed = array.splice(-1); //last item
console.log( 'array:', array );
console.log( 'removed:', removed );
Run code snippetEdit code snippet Hide Results Copy to answer Expand
javascript - How to remove the last element from JQuery array? - Stack Overflow
Remove Property from Nested Objects?
How to get the last item of an array with destructuring
Why not just do array[array.lemth -1]
More on reddit.comWhat's with the trailing commas?
crumbs.last().remove() removes the last matched element from the DOM, it doesn't remove it from the jQuery object.
To remove an element from the jQuery object¹ use slice:
var withoutLastOne = crumbs.slice(0, -1);
¹ Actually this will create a new object that matches one less element instead of modifying your existing object. You will usually not care about the distinction, but should be aware of it.
To remove last element from the array you can use below code too.
var arr = ["item1", "item2", "item3", "item4"];
arr.pop();
Demo