-5
resources: [{
    id: staffId[0].id,
    title: staffId[0].first_name
  },

  {
    id: staffId[1].id,
    title: staffId[1].first_name
  },
  ...
]
                                            ]

Please help me to Write a for-loop in javascript to display the my array.

Eugene Mihaylin
  • 1,736
  • 3
  • 16
  • 31
  • 2
    have you tried writing it yourself? What problem did you face? – Yousaf Oct 11 '18 at 11:07
  • 2
    Can you show us what you tried, so we can help you with that ! – Hiteshdua1 Oct 11 '18 at 11:07
  • Hi, consider showing us what you have tried so far so we can help you to find the problem. – Jerodev Oct 11 '18 at 11:10
  • go and learn some basics and then tried it .. ref. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Loops_and_iteration – Saurabh Yadav Oct 11 '18 at 11:11
  • resources: [ for (var i = 0,var len = staffId.length; i < len; ++i) { id: staffId[i].id , title: staffId[i].first_name }, ], – Ajith Simon Oct 11 '18 at 11:13
  • 3
    Possible duplicate of [Loop through an array in JavaScript](https://stackoverflow.com/questions/3010840/loop-through-an-array-in-javascript) – barbsan Oct 11 '18 at 11:16
  • Welcome to SO, @AjithSimon. You might find reading the site [help section](https://stackoverflow.com/help) useful when it comes to [asking a good question](https://stackoverflow.com/help/how-to-ask). To get the best answers to your question we like to see that you've attempted to solve the problem yourself first, and using a [mcve] in your code that is causing the problem. Asking SO to do all the work for you doesn't help you or us. – Andy Oct 11 '18 at 11:21

1 Answers1

0

If you need to fill resources with staffId values:

const resources = [];
for (let i = 0, l = staffId.length; i < l; i++) { 
  const el = staffId[i];
  resources.push({ id: el.id, title: el.first_name });
};
Eugene Mihaylin
  • 1,736
  • 3
  • 16
  • 31