changed the function from above to be able to change all the key values ββand increase it by 1. And you can go to jsonObj
function replaceByValue( jsonObj, field, oldvalue, newvalue ) { for( var k = 0; k < jsonObj.length; ++k ) { jsonObj[k][field] = (newvalue *1)+k; } return jsonObj; }
//Example
var json = [{ "id": "5001", "type": "None" }, { "id": "5002", "type": "Glazed" }, { "id": "5005", "type": "Sugar" }, { "id": "5003", "type": "Chocolate" }, { "id": "5004", "type": "Maple" }, { "id": "5009", "type": "Juice" }]; json; replaceByValue( json, "id", "na", 123 ); json;
source share