Answer the question
In order to leave comments, you need to log in
Is it possible to implement conditions in JS in an array?
There is an array of user actions:
karta: [
['stop', {}, 1],
['step', "up", { x: 1, y: 2 }, 2],
['step', "up", { x: 2, y: 1 }, 3],
['stop', {}, 4]
],
lvl
, it can be any number. karta: [
['stop', {}, 1],
if (lvl == "12") {
['step', "up", { x: 1, y: 2 }, 2],
} else {
['step', "up", { x: 1, y: 5 }, 2],
},
['step', "up", { x: 2, y: 1 }, 3],
['stop', {}, 4]
],
Answer the question
In order to leave comments, you need to log in
But remember:
As experienced programmers like to joke, if you have a problem and want to solve it with regular expressions, now you have two problems.
karta: [
['stop', {}, 1],
['step', lvl === 12 ? "up" : "down", { x: 1, y: 2 }, 2],
['step', "up", { x: 2, y: 1 }, 3],
['stop', {}, 4]
],
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question