3

I have a json object which has the following form

"data": [{
     "firstName": "XYZ",
     "lastName": "Admin",
     "userId": 1,
     "companyLogo":"Logo"
 }, {
     "firstName": "ABC",
     "lastName": "Admin",
     "userId": 1,
     "companyLogo":"Logo1"
 }, {
     "firstName": "EFG",
     "lastName": "Admin",
     "userId": 1,
     "companyLogo":"Logo2"
 }]

I want the following output to concat the logo name with its path using lodash in nodejs

 "data": [{
     "firstName": "XYZ",
     "lastName": "Admin",
     "userId": 1,
     "companyLogo":"E:/Logo"
 }, {
     "firstName": "ABC",
     "lastName": "Admin",
     "userId": 1,
     "companyLogo":"E:/Logo1"
 }, {
     "firstName": "EFG",
     "lastName": "Admin",
     "userId": 1,
     "companyLogo":"E:/Logo2"
 }]

Is there any function existing which supports this type of concatenation?

1 Answer 1

2

There's no need for an external library:

var data = [
{
  "firstName": "XYZ",
  "lastName": "Admin",
  "userId": 1,
  "companyLogo":"Logo"
 },
 {
  "firstName": "ABC",
  "lastName": "Admin",
  "userId": 1,
  "companyLogo":"Logo1"
 },
  {
  "firstName": "EFG",
  "lastName": "Admin",
  "userId": 1,
  "companyLogo":"Logo2"
 }
]

var new_data = data.map(function(elem){ elem.companyLogo = "E: /" + elem.companyLogo; return elem });

console.log(new_data);
Sign up to request clarification or add additional context in comments.

Comments

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.