Skip to content

Commit 7a167e3

Browse files
committed
obj short technique.. 🚀
1 parent add987c commit 7a167e3

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Longhand:
2+
3+
if (arr.indexOf(item) > -1) {
4+
// Confirm item IS found
5+
}
6+
7+
if (arr.indexOf(item) === -1) {
8+
// Confirm item IS NOT found
9+
}
10+
11+
// Shorthand:
12+
13+
if (~arr.indexOf(item)) {
14+
// Confirm item IS found
15+
}
16+
17+
if (!~arr.indexOf(item)) {
18+
// Confirm item IS NOT found
19+
}

js-coding-technique/obj-entries.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const credits = {
2+
producer: 'Lakshman',
3+
director: 'Gope',
4+
assistant: 'Proddut'
5+
};
6+
const arr = Object.entries(credits);
7+
console.log(arr);
8+
9+
/** Output:
10+
[ [ 'producer', 'Lakshman' ],
11+
[ 'director', 'Gope' ],
12+
[ 'assistant', 'Proddut' ]
13+
]
14+
**/

js-coding-technique/obj-values.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const credits = {
2+
producer: 'Lakshman',
3+
director: 'Gope',
4+
assistant: 'Proddut'
5+
};
6+
const arr = Object.values(credits);
7+
console.log(arr);
8+
9+
/** Output:
10+
[ 'Lakshman', 'Gope', 'Peter' ]
11+
**/

0 commit comments

Comments
 (0)