?
Solved

jquery/javascript remove data from json

Posted on 2011-03-10
2
Medium Priority
?
764 Views
Last Modified: 2012-05-11
Hi -

Hi have a json data string like this:

[ {"id": "3", Name": "Bill"},{"id": "4", Name": "Jack"} ]

Is there a way to remove an element by id?

IE
remove id 4 so the json string would change to:
[ {"id": "3", Name": "Bill"} ]

Thanks in advance



0
Comment
Question by:doctor069
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 2000 total points
ID: 35098918
You may use splice : http://www.w3schools.com/jsref/jsref_splice.asp

var json = [ {"id": "3", "Name": "Bill"},{"id": "4", "Name": "Jack"} ]
function remove(id) {
    for(var j in json) if(json[j]["id"]==id) {
      json.splice(j,1);
      break;
    }
}

remove(4);

Open in new window

Clipboard03.jpg
0
 

Author Closing Comment

by:doctor069
ID: 35099288
Just what I was looking for!

Thanks a lot for your help. Saved me hours
0

Featured Post

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question