- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- 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 fetch a specific value with eval()?
The eval() is used to evaluate an argument in JavaScript. Following is the syntax −
eval(str)
Here, str can be an expression, variable or statement(s).
Let’s say the following is our array −
var studentMarks = [76,34,56,78,81,98,90,59,64];
Now, fetch a specific value with eval(). Here, we are fetching the value at index 1 −
Example
var studentMarks = [76,34,56,78,81,98,90,59,64]; var stringValue = eval("studentMarks"); console.log(stringValue[1]);
To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo80.js.
Output
This will produce the following output −
PS C:\Users\Amit\JavaScript-code> node demo80.js 34
Advertisements