This question already has answers here:
Parse query string in JavaScript [duplicate]
(11 answers)
How can I get query string values in JavaScript?
(73 answers)
Closed 9 months ago.
I'm kind of new to javascript and I was wondering if there was a better alternative to slice. I'm currently using window.location.slice at the moment and it feels like I could be using a better alternative. If you've ever used express.js you might have heard of "req.query.id", something like that in raw javascript would be perfect. Thanks, Alek.
This question already has answers here:
How is almost everything in Javascript an object?
(6 answers)
Why does a primitive variable act like an Object? [duplicate]
(3 answers)
javascript: do primitive strings have methods?
(2 answers)
Closed 2 years ago.
I have this question in mind since I started learning JavaScript last month.
What I have tried?: I researched for it online almost on all good sites but didn't get satisfactory answer in laymans language.
Question: When I create variable let suppose
let name = "mit"
name.toUpperCase()
I am using dot notation to access the method here and I know we use it for something in object. I was confused if the browser creates different object for name variable (which is of string data type here) or what?
This question already has answers here:
Safely turning a JSON string into an object
(28 answers)
Closed 3 years ago.
For example: '[test,abc,123]'. How do you turn that into a standard javascript array that can be iterated?
This will work, but really you should fix your input to give you real JSON as is noted in the comments.
console.log(JSON.parse('["test","abc",123]'));
This question already has answers here:
How can I check if an object is an array? [duplicate]
(51 answers)
Closed 6 years ago.
If so, how can I detect the difference between them.
I've noticed that you can't do typeof Array hence I'm looking for different solution to see the difference.
You can detect if a variable is an array by using Array.isArray(yourArray).
This question already has answers here:
How can I list all the properties of Math object?
(3 answers)
Closed 8 years ago.
Is there a nice way to convert Math object into "real" javascript object?
I want to use Object.keys on Math object. Is that possible to not hardcode it all the way down?
The properties of Math are not enumerable, so Object.keys(Math) returns an empty array.
However, you can use
Object.getOwnPropertyNames(Math)
It will produce something like
["toSource","abs","acos","asin","atan","atan2","ceil","clz32","cos","exp","floor","imul","fround","log","max","min","pow","random","round","sin","sqrt","tan","log10","log2","log1p","expm1","cosh","sinh","tanh","acosh","asinh","atanh","hypot","trunc","sign","cbrt","E","LOG2E","LOG10E","LN2","LN10","PI","SQRT2","SQRT1_2"]