Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

213
Views
How to add array of strings into a property in an array of object?

I have an array of strings

[ '/nft-card', '/landing' ]

I want this array as a property in this object array [{ id: 1, name: 'NFT Preview Card', },{ id: 2, name: 'Remote Landing Page' }]

Result should be like this

[{ id: 1, name: 'NFT Preview Card', link: "/nft-card },{ id: 2, name: 'Remote Landing Page', link: "/landing" }]

How to do this in javascript?

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Assuming both arrays are ordered correctly this can be achieved likes so.

const links = ['/nft-card', '/landing'] // changed the order so the result is what you want

const incompleteObjects = [{ id: 1, name: 'NFT Preview Card', },{ id: 2, name: 'Remote Landing Page' }]

const completeObjects = incompleteObjects.map((item, idx) => 
  {
    return {
      ...item,
      links: links[idx]
    }
  }

EDIT: adjusted links array order

about 4 years ago · Juan Pablo Isaza Report

0

You can make copy of array 2. This is easy way to do:

let ar1=[ '/landing', '/nft-card' ] 

let ar2=[{ id: 1, name: 'NFT Preview Card', },{ id: 2, name: 'Remote Landing Page' }]


let ar3=[]
for(let i=0;i<ar2.length;i++){
  ar2[i].line=ar1[i];
  }
  console.log(ar2)

about 4 years ago · Juan Pablo Isaza Report

0

if the length of your array and your object array is equal you can use this way:

let array = [ '/landing', '/nft-card' ];
let objectArray = [{ id: 1, name: 'NFT Preview Card', link: "nft-card" },{ id: 2, name: 'Remote Landng Page', link: "landing" }];

  for(let i = 0 ; i < array.length; i++){
  objectArray[i].link = array[i];
}

console.log(objectArray);
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!