This question already has answers here:
console.log() async or sync?
(3 answers)
Closed 1 year ago.
When I try to get the page load time using PerformanceEntry I'm able to get an array of data but how do i get only the value of "domComplete" or "duration" instead of the whole list of data; Here's the code:
const time = performance.getEntriesByType("navigation");
console.log(time[0]);
console.log(time[0]['domComplete']);
when i console log (time[0]), this is what i get:
but when using (time[0]['domComplete']) or (time[0]['duration']), it returns 0
Try this
console.log(time[0].domComplete);
Related
This question already has answers here:
How do I return the response from an asynchronous call?
(41 answers)
Closed 3 months ago.
This post was edited and submitted for review 3 months ago and failed to reopen the post:
Original close reason(s) were not resolved
This line of code is getting document count from firestore database it works fine when i call the variable inside the function but outside its undefine.
var LM35TOTALRES; // I WANT TO STORE HERE
db.collection("LM35").get().then(function(querySnapshot) {
LM35TOTALRES = querySnapshot.size //DATA THAT I WANT
console.log(LM35TOTALRES); // THIS IS WORKING
});
console.log(LM35TOTALRES); // NOT WORKING
I believe this is because the function is async so it finishes setting the value after the log outside, One solution is to return the value needed in the variable directly and await it like so const LM35TOTALRES = await (db.collection("LM35").get()).size
This occurs due event loop scheduling you can find some good examples in this video about min 2 or so
use let instead of var
let LM35TOTALRES;
This question already has answers here:
get the second to last item of an array?
(11 answers)
Closed 10 months ago.
I wanna to get one before last element of array in JavaScript. but in console, when I use this code "array.length -2"dose not work, and it just return me the length of array minus 2.
and when I use this code "array.at[-2]" it returns "undefined"!
const arr = [1,2,3,4,5,6]
console.log(arr[arr.length -2])
//5
This question already has answers here:
HTTP GET request in JavaScript?
(31 answers)
Read a file in Node.js
(8 answers)
Closed 3 years ago.
I need to read the numeric value of one line in a text file
color=7
so var color will = 7
Split the string by '=', get the second value and turn it into an int:
let data = 'color=7';
let color = parseInt(data.split('=')[1]);
console.log(color);
Do note that if the value after the = isn't a number in this case, the code will throw an excpetion so you might wanna catch it.
This question already has answers here:
How can I get query string values in JavaScript?
(73 answers)
Closed 7 years ago.
I want to pass one value through ajax by taking the values from jQuery. But I am using link so I have problems taking the value. I tried the following,
<a id="addpa" class="ActionPopup" href="http://localhost:49951/admin/assignhome/Add?sPId=7">Add</a>
Jquery Code:
var spId = $("#addpa").prop("href"); // Here i am getting a whole Url
var thequerystring = getParameterByName("sPId");
The result is showing undefined. How to take the value of sPId? Give me ideas..
How to take the value of sPId?
Try using String.prototype.split() , Array.prototype.pop()
var spId = $("#addpa").prop("href").split(/=/).pop();
This question already has answers here:
How can I access and process nested objects, arrays, or JSON?
(31 answers)
Closed 9 years ago.
I have this json array
var currencyformats =
{"USD":[
{'symbol':'$', 'left':true}
],
"UAH":[
{'symbol':'₴', 'left':true}
],
"EUR":[
{'symbol':'€', 'left':false}
]
};
How retreive '₴' ?
I tried this (in cookie "to" I've "UAH")
currencyformats[$.cookie("to")].symbol
but I've obtained undefined
The problem is that under each country code, you've defined an array with a single object. That means that after you access the country code, you'll need to also access the first index in the array.
So, assuming the cookie is set to the value that you're expecting:
currencyformats[$.cookie("to")][0].symbol;