-1

I would like to get 'experiments[0].name' but I have error that name is not defined. How to get this property?

let experiments = [ {name: "C200929R01_SizeMarker", file: experiments[0].name + ".xrrx"} ];

siw1171
  • 9
  • 1
  • Set `experiments[n].file` *after* initializing `experiments` (with just the `name` property). – jarmod Jun 27 '22 at 16:24

2 Answers2

0

Until that closing ] experiments indeed won't be defined.

If your just trying to save typing the name in twice, you could retructure like ->

const name = "C200929R01_SizeMarker";
let experiments = [ {name, file: name + ".xrrx"} ];

console.log(experiments);
Keith
  • 22,005
  • 2
  • 27
  • 44
0
let experiments = [ {name: "C200929R01_SizeMarker", file: experiments[0].name + ".xrrx"} ];

When you are asigning file: experiments[0].name, experiments[0] is not defined yet, so you have different options:

let experiments = [{name: "C200929R01_SizeMarker"}];
experiments[0].file = experiments[0].name + ".xrrx";

Or using the option described in the previous answer