-2

If I have json Object Say.

<script>
$(function () {
    var tr;
    var obj = [{ obj1: { "name": "v1", nestobj: [{ "value": "10" }, { "value": "20" }, { "value": "30" }] } }];

    obj.push({ obj1: { "name": "v2", nestobj: [{ "value": "abc" }, { "value": "xyz" }] } });

    for (var i = 0; i < obj.length; i++) {
        tr = $("<tr id='a3'/>");
        $('p').css('border-top', '5px');
        $('p').css('border-color', 'black');

        tr.append("<td id='a2'>" + obj[i].obj1.name + "</td>")
        $('tbody').append(tr);

        for (var j = 0; j < obj[i].obj1.nestobj.length; j++) {

            tr.append("<p>" + obj[i].obj1.nestobj[j].value + "<input type='button' value='remove value' style='color:blue;' onclick=''></p>")
            $('tbody').append(tr);
        }                    
    }   
});

can I remove 'nestobj' using button onclick function so it becomes:

  • 3
    What you have is a JavaScript array containing objects. There is no JSON here. – Felix Kling Dec 14 '16 at 07:24
  • yap there is json @felix kling – mozammal hossain Dec 14 '16 at 07:25
  • 5
    No, there is not. JSON is a textual data format, like XML, YAML or CSV. You have JavaScript code. Please read [What is the difference between JSON and Object Literal Notation?](http://stackoverflow.com/q/2904131/218196) to learn more about the difference. Either way, your question is unclear. I can't spot the difference between the existing objects and the desired result. Do you just want to delete a property of an object? Or do you want to remove an element from an array? – Felix Kling Dec 14 '16 at 07:27
  • thanks i will clear that – mozammal hossain Dec 14 '16 at 07:40
  • how to delete 'nestobj' ' value ' using button onclick function – mozammal hossain Dec 14 '16 at 07:42

1 Answers1

0

In your button on-click event put this below

delete obj["nestobj"];

Rjoydip
  • 66
  • 3