var arr = [{id:1,"name":"John"},{id:2,"name":"James"}]
$.each(arr, function(){
if(this.id == 1){
//change john to Johnathan
}
});
without using key, is it possible to alter array object?
See Question&Answers more detail:osvar arr = [{id:1,"name":"John"},{id:2,"name":"James"}]
$.each(arr, function(){
if(this.id == 1){
//change john to Johnathan
}
});
without using key, is it possible to alter array object?
See Question&Answers more detail:osSure you can do that by converting the object to a string if you are looking for a hack. What is it that you are looking to do?
var arr = [{id:1,"name":"John"},{id:2,"name":"James"}]
$.each(arr, function(i){
if(this.id == 1){
arr[i] = JSON.parse(JSON.stringify(this).replace("John", "Johnathan"))
}
});