0

This is my req.body json data from angularjs controller:

{ 
    phoneno: [ 
               { id: 1, gsm: '123457801',  firstName: 'Mohamed',  lastName: 'Sameer'},
               { id: 2, gsm: '123450987',  firstName: 'Hameed',   lastName: 'Basha' } 
             ],
    sender: 'ifelse',
    message: 'Hello Test' 

}

i want to get gsm values from req.body

I want to make the above structure into this type:

[{phoneno:123457801;sender:'ifelse';message:'Hello Test'},{phoneno:123450987;sender:ifelse;message:'Hello Test'}]

then only i am able to insert in mysql.

1 Answer 1

3

I think it will helpful to you!...

var body={ 
    phoneno: [ 
               { id: 1, gsm: '123457801',  firstName: 'Mohamed',  lastName: 'Sameer'},
               { id: 2, gsm: '123450987',  firstName: 'Hameed',   lastName: 'Basha' } 
             ],
    sender: 'ifelse',
    message: 'Hello Test' 

};
var new_req_body=[];
for(var i=0;i<body.phoneno.length;i++){

var new_arr={
            sender:body.sender,
            message:body.message,
            phoneno:body.phoneno[i].gsm
          };
new_req_body.push(new_arr);
}
console.log(new_req_body);

Sign up to request clarification or add additional context in comments.

2 Comments

@kaiaiselvan you there? another problem
post it as a separate question and send me a link

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.