Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add: Add JS Loop #182

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
for-in-loop
  • Loading branch information
thepravin committed Jan 18, 2024
commit 9de5b48ebe07d9c635b38451de5240117f2ee32e
32 changes: 32 additions & 0 deletions JsLoops/for-in-loop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# JavaScript For...In Loop

The `for...in` loop in JavaScript is used to iterate over the properties of an object. It is particularly useful when you want to loop through the keys (property names) of an object.

## Syntax

```javascript
for (variable in object) {
// code to be executed
}
```
```variable:``` A variable that will be assigned the property name on each iteration. <br/>
```object:``` The object whose enumerable properties are iterated.
## Note
The for...in loop iterates over enumerable properties, including inherited ones. <br/>
It is recommended to use caution when using for...in with arrays, as it may iterate over array methods and not just array elements.

### Example
```javascript
// Sample object
const car = {
make: 'Toyota',
model: 'Camry',
year: 2022
};

// Using for...in loop to iterate over object properties
for (let key in car) {
console.log(key + ': ' + car[key]);
}

```