1

My code looks like this. At the beginning I have defined nested arrays

var license= [{ 
    packet: [{
        pay: [],
        channel: [],
        fun: []
    }] 
}];

Add item work corect

function addPayChannelToObject(name) {

    var paychannel = { name: name };
    license[0].packet[0].pay.push(paychannel);

    console.log(pay);
}

How can I delete an item by value?

function removeItemFromObject(name) {

    //??
    console.log(pay);
}
1
  • You seem to know how to access the nested array, and the remaining question "delete an item by value" is a plain duplicate. Commented Jun 26, 2014 at 12:54

1 Answer 1

0

Try this way

 function removeItemFromObject(name) {

     var index = license[0].packet[0].pay.indexOf(name); // found index of value
     if(index > -1){
       license[0].packet[0].pay.splice(index, 1); //remove index
     }
     console.log(pay);
   }
Sign up to request clarification or add additional context in comments.

1 Comment

if indexOf results in -1 it will remove the last item, though none were found

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.