Number value is getting changed in JS [duplicate] - javascript

This question already has answers here:
What is JavaScript's highest integer value that a number can go to without losing precision?
(21 answers)
Is there any limitation for integer in javascript? [duplicate]
(2 answers)
Closed 6 years ago.
This is my post id:
var postId = 47213486358396931;
var postComments = "Comment";
adding in object like this
var param = {
"PostId" : postId,
"postComment":postComments
}
If I print the param I get like this. The last digit of number changed to 0. Why am getting like this.
{"PostId" : 47213486358396930, "postComment": "Comment"}

Related

Unable to add two variables in javascript [duplicate]

This question already has answers here:
Adding two numbers concatenates them instead of calculating the sum
(24 answers)
How to force addition instead of concatenation in javascript [duplicate]
(3 answers)
Closed 12 days ago.
I am working with javascript and right now trying to sum(add/plus) two variables but right now instead of "addition"(plus) variables are "concate",Here is my current code
var first = this.value; // getting value "5"
var second =$("#earning").val(); // getting value "2"
var final_value =first + second;
M
y expected result is "7"(5+2) but its giving me "52",how can i fix this ?

MongoDB $sort cant sort by two parameters [duplicate]

This question already has answers here:
Sorting on Multiple fields mongo DB
(4 answers)
JavaScript set object key by variable
(8 answers)
Closed 8 months ago.
I have the following code :
{ "$sort" : {sortParam : sortOption}},
it should work but it interpretates it as Im trying to set a value to sortParam. Is there a way I can escape this ?

Read A Line In Text File with JavaScript [duplicate]

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.

How to take a value from a link using jquery [duplicate]

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();

Swap values of keys in JSON array [duplicate]

This question already has answers here:
Swap value of two properties on object(s)
(3 answers)
Closed 8 years ago.
I have the following JSON. I need to swap SortId
Like I have this,
[{"CategoryId":1,"Name":"Worktable","SortId":1}
,{"CategoryId":2,"Name":"Bf ","SortId":2}]
After swaping their 'SortId' I need
[{"CategoryId":1,"Name":"Worktable","SortId":2}
,{"CategoryId":2,"Name":"Bf ","SortId":1}]
Please tell me how to do it through JavaScript.
var tmp = a[0].SortId;
a[0].SortId = a[1].SortId;
a[1].SortId = tmp;
jsFiddle

Categories

Resources