screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html> <head> <title>String to Number Conversion</title> <script> function convertStringToNumbers() { const stringArray = ["1", "2", "3", "4", "5"]; // Using Number() constructor const numberArray1 = stringArray.map((str) => Number(str)); // Using parseFloat() function const numberArray2 = stringArray.map((str) => parseFloat(str)); // Displaying the original array document.getElementById("originalArray").textContent = JSON.stringify(stringArray); // Displaying the converted arrays document.getElementById("output1").textContent = JSON.stringify(numberArray1); document.getElementById("output2").textContent = JSON.stringify(numberArray2); } </script> </head> <body> <h2>Javascript Convert Array of string into Array of number</h2> <button onclick="convertStringToNumbers()">Convert</button> <h2>Original String Array:</h2> <p id="originalArray"></p> <h2>Output using Number() constructor:</h2> <p id="output1"></p> <h2>Output using parseFloat() function:</h2> <p id="output2"></p> </body> </html>