Get the App
SLTechnology News&Howtos  ›  Development  › 

Description and example usage of eval method in javascript

Shulou Source: shulou.com Published: 2022-06-03 17:09:46 11月13日 Update

This article introduces the knowledge of "explanation and example usage of eval method in javascript". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

1. Eval is a function property of the global object that evaluates a string and executes the JavaScript code in it.

2. The function syntax is eval (string).

3. The parameter string represents the string to be calculated.

Return value: the value obtained by calculating the string, if any.

Example

`function getDescendantantProp (obj, desc) {var arr = desc.split ('.'); while (arr.length) {obj = obj [arr.shift ()];} return obj;} var obj = {a: {b: {c: 0}; var propPath = getPropPath (); / / returned, such as "a.b.c" var result = getDescendantantProp (obj, propPath); this is the end of the description and example usage of eval method in javascript. Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Examples methods content functions characters strings more knowledge practicality learning next code global parameters dilemma actual objects properties situations articles Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info MariaDB Shulou Information vpn NVidia