I stumbled upon this code snippet:
var B = [];
var data = [];
data.push("string");
// ....
B.push(data);
// ...
for each (var A in B){
console.log(B);
console.log(A);
let obj = A[0].split("|", 3);
console.log(obj[0]);
console.log(obj[1]);
}
It appears that B is an array of arrays. When I printed B, it looked like this:
[
[
"1+!|6789|1234",
"15:00"
],
[
"2+!|1234|4567",
"16:00"
]
]
Also, when I printed obj
:
["!1+", "6789", "1234"]
["2+!", "1234", "4567"]
everything seemed to be in order. The code runs without any issues and all functionalities are working correctly. However, my VScode throws a syntax error and upon researching, I found this:
https://developer.mozilla.org/en-US/docs/Archive/Web/JavaScript/for_each...in
Following that, I attempted:
- removing
each
and usingof
- removing
each
and retainingin
- keeping
each
and usingof
Option 1 resulted in a crash with the error:
SyntaxError: missing ; after for-loop initializer
For option 2, when I tried to print A
, it showed 0
, which is clearly incorrect.
Option 3 led to a crash with the error:
SyntaxError: invalid for each loop
So, how should I modify it? My assumption is that the old code is correct but deprecated, and I require a replacement that functions in the same way. Thank you!