0

Below there are 6 variables with some values , I have to push this data in Array "socialMediaDetail" in below format ,how can I do that ? Please help suggest . This is kind off example ,Please help .

// Below 6 variables .
const Twittername = 'twitter';
const Twitterlink = 'HARIRAM @twitter.com';
const facebookname = 'facebook';
const facebooklink = 'VarnaHERO @facebook.com';
const linkedInname = 'linkedIn';
const linkedIlink = 'linkedIn @linkedin.com';

// in below format I have to store in array . 
const socialMediaDetail = [{
  "name": "twitter",
  "link": "[email protected]"
}, {
  "name": "facebook",
  "link": "[email protected]"
}, {
  "name": "linkedIn",
  "link": "[email protected]"
}];

Thanks

2 Answers 2

2

The simplest way of doing that is to just use the variables while initializing the socialMediaDetail array:

const socialMediaDetail = [{
  name: Twittername,
  link: Twitterlink
}, {
  name: facebookname,
  link: facebooklink
}, {
  name: linkedInname,
  link: linkedIlink
}]
Sign up to request clarification or add additional context in comments.

Comments

2

just initialize an array with value as a variable name.

const socialMediaDetail = [{
  "name": Twittername,
  "link": Twitterlink
}, {
  "name": facebookname,
  "link": facebooklink
}, {
  "name": linkedInname,
  "link": linkedIlink
}];

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.