How can JS set values for variables in a chain, like
var date = date[0] = the_creation_of_information.split('., '); As far as I know, this is possible in PHP, but in JS?
How can JS set values for variables in a chain, like
var date = date[0] = the_creation_of_information.split('., '); As far as I know, this is possible in PHP, but in JS?
In ES2015 there is not even needed in the indexer. You can use destructuring assignment
var [date] = "1887-1888 гг., Италия".split('., '); console.log(date); The '=' operator in JS works from right to left.
That is, your entry is equivalent to the following:
var date date[0] = the_creation_of_information.split('., '); date = date[0] which will cause an error, since the second line has date = undefined, and therefore date has no date [0] property.
You cannot assign an array to a date variable and its null element at the same time. But you don’t have to assign an array anywhere!
The index operator ( [] ) works with any expressions, not just variables.
var date = the_creation_of_information.split('., ')[0]; Source: https://ru.stackoverflow.com/questions/573981/
All Articles