AmitDiwan has Published 10744 Articles

Behavior of + operator in JavaScript to store large numbers?

AmitDiwan

AmitDiwan

Updated on 03-Oct-2020 12:38:27

3K+ Views

To store large numbers in JavaScript, use BigInt() rather than + operator. If you will use the + operator, then expect loss of precision.Let’s say the following is our large number and we are storing using BigInt() −console.log("Loss of precision with + operator..")ExampleFollowing is the code −var stringValue1="100"; console.log("The integer ... Read More

How to populate select list with jQuery?

AmitDiwan

AmitDiwan

Updated on 01-Oct-2020 13:42:21

11K+ Views

To populate select list with jQuery, use for loop along with append() and append the options to the already created select.Let’s say we have the following select with options − John David ExampleFollowing is the code to append more number of options using append() − Live Demo     ... Read More

Convert integer array to string array in JavaScript?

AmitDiwan

AmitDiwan

Updated on 01-Oct-2020 13:38:04

567 Views

To convert integer array to string array, use the map(String) in JavaScript. Let’s say the following is our integer array −var integerValues = [101, 50, 70, 90, 110, 90, 94, 68];Convert integer array to string array −integerValues.map(String);ExampleFollowing is the code −var integerValues = [101, 50, 70, 90, 110, 90, 94, ... Read More

How to print div content using jQuery?

AmitDiwan

AmitDiwan

Updated on 01-Oct-2020 13:33:17

6K+ Views

Let’s say we have the following button −On click of the above button, call the function() with on() −$('#buttonId').on('click', function () {    displayTheData(); })The above function is using the html() to display the following div −    I am inside the div tag... ExampleFollowing is the complete code to ... Read More

Manipulate two selects on page load with jQuery

AmitDiwan

AmitDiwan

Updated on 01-Oct-2020 13:20:39

476 Views

Let’s say the following is our first select −    John    David    Bob    Mike    Sam    Carol Following is our second select −    David    Mike    Carol We need to remove the options in the first select, which are similar to options in the ... Read More

How to sort date array in JavaScript

AmitDiwan

AmitDiwan

Updated on 01-Oct-2020 11:09:15

453 Views

Suppose we have an array that contains some dates like this −const arr = [    [ '02/13/2015', 0.096 ],    [ '11/15/2013', 0.189 ],    [ '05/15/2014', 0.11 ],    [ '12/13/2013', 0.1285 ],    [ '01/15/2013', 0.12 ],    [ '01/15/2014', 0.11 ],    [ '02/14/2014', 0.11 ], ... Read More

Recursive string parsing into object - JavaScript

AmitDiwan

AmitDiwan

Updated on 01-Oct-2020 11:06:42

533 Views

We are required to write a JavaScript function that takes in an array of strings and returns an object corresponding to the strings.For example −If the array is −const arr = [    "country.UK.level.1",    "country.UK.level.2",    "country.US.level.1",    "country.UK.level.3" ];Then the output should be −const output = {   ... Read More

How to join JavaScript array of string

AmitDiwan

AmitDiwan

Updated on 01-Oct-2020 11:03:47

147 Views

We are required to write a JavaScript function that takes in an array of strings. The function should join all the strings of the array, replace all the whitespaces with dash "-", and return the string thus formed.For example: If the array is −const arr = ["QA testing promotion ", ... Read More

JavaScript Algorithm - Removing Negatives from the Array

AmitDiwan

AmitDiwan

Updated on 01-Oct-2020 11:02:20

300 Views

Given an array X of multiple values (e.g. [-3, 5, 1, 3, 2, 10]), We are required to write a function that removes any negative values in the array.Once the function finishes its execution the array should be composed of just positive numbers. We are required to do this without ... Read More

Finding number that appears for odd times - JavaScript

AmitDiwan

AmitDiwan

Updated on 01-Oct-2020 11:00:01

168 Views

Given an array of integers, we are required to write a function that takes this array and finds the one element that appears an odd number of times. There will always be only one integer that appears an odd number of times.We will approach this problem by sorting the array. ... Read More

Advertisements