

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
JavaScript Convert an array to JSON
To convert an array to JSON in JavaScript, the code is as follows −
Example
<!DOCTYPE html> <html> <head> <style> body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } </style> </head> <body> <h1>Converting an array to JSON</h1> <button class="Btn">CLICK HERE</button> <p class="sample"></p> <h3>Click the above button to convert the array into JSON</h3> <script> let sampleEle = document.querySelector(".sample"); let arr = [22, "A", 1, "HELLO", "J", 9, 22]; sampleEle.innerHTML = arr + "<br>"; document.querySelector(".Btn").addEventListener("click", () => { sampleEle.innerHTML += JSON.stringify(arr); }); </script> </body> </html>
Output
On clicking the “CLICK HERE” button −
- Related Questions & Answers
- Convert JSON array into normal json in JavaScript
- How to convert an array to JSON Array using JSON-lib API in Java?
- How to convert JSON text to JavaScript JSON object?
- From JSON object to an array in JavaScript
- Convert JSON to another JSON format with recursion JavaScript
- JavaScript creating an array from JSON data?
- How to convert Java Array/Collection to JSON array?
- How to convert JSON Array to normal Java Array?
- How to convert a JSON array to array using JSON-lib API in Java?
- How to convert an array into JavaScript string?
- JavaScript - Convert an array to key value pair
- How to convert XML to JSON array in Java?
- How to convert an array into a complex array JavaScript?
- How to convert an object into an array in JavaScript?
- Formatting dynamic json array JavaScript
Advertisements