Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

add json object to json array javascript


var jsonStr = '{"theTeam":[{"teamId":"1","status":"pending"},{"teamId":"2","status":"member"},{"teamId":"3","status":"member"}]}';

var obj = JSON.parse(jsonStr);
obj['theTeam'].push({"teamId":"4","status":"pending"});
jsonStr = JSON.stringify(obj);
// "{"theTeam":[{"teamId":"1","status":"pending"},{"teamId":"2","status":"member"},{"teamId":"3","status":"member"},{"teamId":"4","status":"pending"}]}"

Comment

node js add new object to object array json

var jsonStr = '{"theTeam":[{"teamId":"1","status":"pending"},{"teamId":"2","status":"member"},{"teamId":"3","status":"member"}]}';

var obj = JSON.parse(jsonStr);
obj['theTeam'].push({"teamId":"4","status":"pending"});
jsonStr = JSON.stringify(obj);
// "{"theTeam":[{"teamId":"1","status":"pending"},{"teamId":"2","status":"member"},{"teamId":"3","status":"member"},{"teamId":"4","status":"pending"}]}"
Comment

PREVIOUS NEXT
Code Example
Javascript :: evento tecla enter javascript 
Javascript :: component will unmount 
Javascript :: js array as parameter 
Javascript :: mariadb JSON_ARRAYAGG does not exist 
Javascript :: materialize dropdown js 
Javascript :: javascript string new line 
Javascript :: redux toolkit remove from array 
Javascript :: javascript goto page 
Javascript :: list of alphabet letter english for js 
Javascript :: array flatten 
Javascript :: react-query dependent query 
Javascript :: query string to object javascript 
Javascript :: check last url in javascript 
Javascript :: paper js text example 
Javascript :: use of split and join 
Javascript :: global execution context javascript 
Javascript :: animate change of class angular 
Javascript :: node red debug to console 
Javascript :: javascript regex grouping replace 
Javascript :: GET method firebase realtime database react 
Javascript :: nodejs global 
Javascript :: js array push 
Javascript :: mongodb insertmany 
Javascript :: js if not undefined or null 
Javascript :: save previousdata react 
Javascript :: npm install --save react-draft-wysiwyg draft-js react-draft-wysiwyg-a 
Javascript :: substr method 
Javascript :: how to write query string js 
Javascript :: mong db connect error 
Javascript :: bootstrap modal close on form submit in react 
ADD CONTENT
Topic
Content
Source link
Name
5+9 =