I have a problem for delete an Object in an array. I think the solution is very simple but I am not good in javascript.
I want to delete the value in this array but I have a problem because of its something like that in js:
myArray = [Object1,Object2,...]
and in the object
Object1 = {SUM: "-0.75" , mont: "1", name: "test", **value: "{"25":"test"}**, year: "2017"}
Thanks for your help.
4 Answers 4
You could use the right element of the array and and the property of the object with a property accessor and the delete operator.
delete myArray[0].value;
//^^^^ delete operator
// ^^^^^^^ array
// ^^^ index of array
// ^^^^^ property
answered Feb 24, 2017 at 11:31
Nina Scholz
388k26 gold badges367 silver badges417 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
You can use several methods to remove an item from it:
//1
someArray.shift(); // first element removed
//2
someArray = someArray.slice(1); // first element removed
//3
someArray.slice(0,1); // first element removed
//4
someArray.pop(); // last element removed
if you want to remove element at position x, use:
someArray.slice(x,1);
answered Feb 24, 2017 at 11:36
savani sandip
4,4841 gold badge13 silver badges8 bronze badges
1 Comment
Nina Scholz
funny, i think it is to remove a property of the object, not to remove an element of the array ...
var Arr = [{value:"xyz",name:"ajhs"},{value:"xyz",name:"jask"}]
delete(Arr[1].value)
this will delete value from object at index 1
answered Feb 24, 2017 at 11:33
Ankit Raonka
6,94710 gold badges40 silver badges56 bronze badges
Comments
myArray = [Object1,Object2,...]
If you want to remove element at position ,
myArray .splice(indexPosition,1);
answered Feb 24, 2017 at 11:44
Amol B Lande
2521 gold badge2 silver badges13 bronze badges
2 Comments
B.Denis
thank, for your answers but is for remove property of the object in my array, not to remove an element of the array
Amol B Lande
to remove property in array used:developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…
lang-js