What is for each...in a statement in JavaScript?

JavascriptWeb DevelopmentFront End Technology

The for each...in loop iterates a variable overall value of the properties of objects. 

Note − The “for…each..in” is now deprecated. Do not use. 

Syntax

Here’s the syntax −

for each (variablename in object) {
   statement or block to execute
}

Example

Here’s an example, which will not run on any of the web browsers, since “for each..in” is now deprecated −

<!DOCTYPE html>
<html>
   <body>
      <script>
         var myObj = {myProp1:30, myProp2: 40};
         var sum = 0;
         for each (var value in myObj) {
            sum += value;
         }
         document.write(sum);
      </script>
   </body>
</html>
raja
Published on 07-Feb-2018 13:32:44
Advertisements