Get the specified element in the array
P粉191323236
P粉191323236 2023-08-17 11:20:25
0
1
581
<p>I get the output of <strong>[Document<Recording<string, any>>, number][]</strong> Each element is described below: </p> <pre class="brush:php;toolbar:false;">[ Document{ page: 'I worked at ABC Company', meta: { id: emloyee-111, name: 'John"} }, 245 ] [ Document{ page: 'I am a software developer', meta: { id: emloyee-444, name: 'Marry"} }, 789 ] for (employee of employees) { // Get id // get name // Get the numbers 245, 789 }</pre> <p>In typescript (or javasSript), how to get the numbers (245, 789) of two employees and their id and name. </p>
P粉191323236
P粉191323236

reply all(1)
P粉268654873

Just loop through the output

for (const [doc, num] of output) {
  const { id, name } = doc.employee;
  console.log({ id, name, num });
}

Or if you want to get data from an array of employees:

for (const employee of employee) {
  const entry = output.find(([doc]) => doc.employee.id === employee.id);

  if (entry) {
    const [doc, num] = entry;
    const { id, name } = employee;
    console.log({ id, name, num });
  }
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template