Linked Questions
13 questions linked to/from Unpacking array into separate variables in JavaScript
-2
votes
3
answers
347
views
Dual variable assignment in JavaScript [duplicate]
If you have a JavaScript function that returns two values, is it possible to assign those values to two variables in a single statement?
For example, in Python it might look like:
(var1, var2) = ...
0
votes
0
answers
39
views
Easiest Way to Assign Array to Individual Objects in Typescript? [duplicate]
In python you can do:
goat, cabbage, wolf, farmer = puzzle.passengers
where array is a list of some type.
Is there a quick way to do the samething in typescript?
I tried:
var goat: Passenger, ...
78
votes
4
answers
105k
views
Split a string straight into variables
I’d like to know if standard JS provides a way of splitting a string straight into a set of variables during their initial declaration. For example in Perl I would use:
my ($a, $b, $c) = split '-', $...
39
votes
3
answers
22k
views
Python-like unpacking in JavaScript
I have the following string
output_string = "[10, 10, [1,2,3,4,5], [10,20,30,40,50]]"
Then I JSON.parse it
my_args = JSON.parse(output_string)
How do I unpack it in a Python-like way so that every ...
Kit's user avatar
- 31.7k
5
votes
3
answers
1k
views
JavaScript alternatives
In some projects that I work, was added some blocks with this syntax:
var [code, name] = input.split("/");
console.log(code);
console.log(name);
I really like this, is so simple and small. It's true ...
0
votes
2
answers
753
views
Get Text From Textarea, and Storing Each Line in a Separate Variable
I'd like to make a custom order form for my website which will allow customers to input a custom engraved message into a textarea. Customers can engrave a maximum of 3 lines.
I'd like to collect the ...
0
votes
1
answer
260
views
how tosplit the value and store in different variable in javascript
My code has a variable that contains the multiple value something like:
var GlobalOpportunityTypeID="8|9|10"
I want to split this value into different variables as per my requirement. How can I do ...
0
votes
2
answers
118
views
Better way to handle operations with many variables?
I have around 30 values stored as variables:
var a = 1,
b = 2,
c = 3,
...
z = 26,
aa = 27,
ab = 28;
that I want to scale. I do so using an array:
array = [a, b, c];
var ...
0
votes
3
answers
126
views
How to reset counter once it reaches zero
I got 7 variables (seconds), I am using them to show countdown. All of them counting down simultaneously at the same page. I want to set them to '59' after they reached to '0'.
Here is my code :
s--; ...
0
votes
1
answer
57
views
How to create an individual array from an array of object
How do I split an array into individual array:
[1,2,3,4,5] => [1][2][3][4][5]
The array of objects is gotten from a backend API
const arr = [
{
id: '1',
name: 'Emmanuel',
...
},
{
...
0
votes
2
answers
54
views
exporting a variable and getting access to it
I'm using the code below to get access to variables in variables.js from main.js:
variables.js:
export default {
bla: 123,
}
main.js:
var vars = require('./variables').default;
class MyClass ...
-1
votes
1
answer
62
views
Can someone help me to undestand "For of" ECMA6?
i wanna understand those results, why [key, value] work that way ? i dont understand how [key, value] return different in both code bellow since both are ECMA 6
let iterable = new Map([['a', 1], ['b',...
0
votes
0
answers
61
views
How to perform Array/Object destructuring manually & efficiently?
Array destructuring is super useful:
var [a, b, c] = [1, 2, 8];
It looks like it was implemented into Javascript 1.7, but then removed with bug 1083498. Now according to this table it's not supported ...