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

94
Views
data maping facing issue to conver data given below

hi everyone i have data given below

nodes data

var nodes=[
  {
    name:'shanu',
    value:5
  },
  {
    name:'bhanu',
    value:2
  },
  {
    name:aaditya,
    value:1
  }
]

edge data

var edge =[
  {
    source:'shanu',
    target:'aaditya'
  },
  {
    source:'shanu',
    target:'bhanu'
  },
  {
    source:'aaditya',
    target:'bhanu'
  }
]

Now I just want to convert edge data source and target based on id

output I want from above data

var convertedEdge=[
  {
    source:0,
    target:2
  },
  {
    source:0,
    target:1
  },
  {
    source:1,
    target:2
  }
]
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

you need to use two loops:

var convertedEdge = [], source = '', target = '';
for (i in edge) {
   source = edge[i].source;
   target = edge[i].target;
   for(j in nodes) {
        if (source == nodes[j].name) {
            source = j
          }
        if (target == nodes[j].name) {
           target = j
          }
   }
     convertedEdge.push({
       source: source,
       target: target
     })
}
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!