0

I'm using the platform of Google Earth Engine.

I have my list of variables, and what i want is to assign each value of i to each variable

var Y03, Y04, Y05, Y06, Y07, Y08,Y09, Y10, Y11, Y12,Y13, Y14, Y15,Y16, Y17, Y18;

var Years = [ Y03, Y04, Y05, Y06, Y07, Y08,Y09, Y10, Y11, Y12,Y13, Y14, Y15,Y16, Y17, Y18];

for (var i = 2003; i <= 2018; i++){
  Years[i] = i; 
}
print(Y05); //undefined

As you can see, when i use print(Y05), the result is undefined and i want 2005.

2 Answers 2

2

You can easily assign values to variables using Array destructuring like:

var [Y03, Y04, Y05, Y06, Y07, Y08,Y09, Y10, Y11, Y12,Y13, Y14, Y15,Y16, Y17, Y18] 
  = Array.from({length: 16}, (x, i) => 2003 + i)

console.log( Y05 )
console.log( Y03, Y18 )

Sign up to request clarification or add additional context in comments.

Comments

0

You can not assign values to variable in this way. If you print(Years) than you can see the updated values

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.