in · of
in
checks whether a property key/index exists on an object (including its prototype chain).of
appears infor...of
andfor await...of
to iterate values from an iterable (arrays, strings, Maps, Sets, etc.).
Syntax
// in operator
key in object
// for...of (values)
for (const value of iterable) { /* ... */ }
// for await...of (async values)
for await (const value of asyncIterable) { /* ... */ }
Examples
// ১) 'মধ্যে' দিয়ে প্রপার্টি চেক
const ব্যবহারকারী = { নাম: "Mamun", শহর: "Dhaka" };
কনসোল.লগ("নাম" মধ্যে ব্যবহারকারী); // true
কনসোল.লগ("দেশ" মধ্যে ব্যবহারকারী); // false
// প্রোটোটাইপ‑চেইনসহ চেক করে
কনসোল.লগ("toString" মধ্যে ব্যবহারকারী); // true (Object প্রোটোটাইপ)
// নিজের প্রপার্টি যাচাই করতে
কনসোল.লগ(Object.hasOwn(ব্যবহারকারী, "নাম")); // true
// অ্যারের ইনডেক্স অস্তিত্ব (hole গোনে)
const A = [10, , 30]; // A[1] missing hole
কনসোল.লগ(1 মধ্যে A); // true ← hole ও গণ্য
কনসোল.লগ(A[1] === undefined); // true ← মান undefined
// ২) 'প্রতি...এর' — ভ্যালু ইটারেশন
const সংখ্যা = [2, 4, 6];
প্রতি (const n এর সংখ্যা) {
ছাপাও(n * n);
}
// স্ট্রিং
প্রতি (const ch এর "Bn") {
কনসোল.লগ(ch);
}
// Map/Set
const ম্যাপ = new Map([["a", 1], ["b", 2]]);
প্রতি (const [কী, মান] এর ম্যাপ) {
দেখাও(কী, মান);
}
const সেট = new Set([1, 2, 2, 3]);
প্রতি (const v এর সেট) কনসোল.লগ(v);
// ৩) 'প্রতি...মধ্যে' (for...in) — কী ইটারেশন (সতর্কতা)
const অবজ = { a: 1, b: 2 };
প্রতি (const কী মধ্যে অবজ) {
কনসোল.লগ(কী, "=>", অবজ[কী]); // কী‑গুলো দেয়
}
// অ্যারেতে for...in এড়িয়ে চলুন—অর্ডার/হোল ইস্যু হতে পারে
Notes
in
returnstrue
for properties found anywhere in the prototype chain. For own‑properties only, useObject.hasOwn(obj, key)
.- On arrays,
index in arr
checks for presence of a slot (including holes), not the value; the value could still beundefined
. for...of
iterates values from iterables (Array, String, Map, Set, generators).for...in
iterates keys (enumerable property names) and should be avoided on arrays.of
is not a standalone operator; it’s part of the loop syntaxfor (... of ...)
andfor await (... of ...)
.- Prefer
for...of
or array helpers (map
,filter
,forEach
) for arrays; usefor...in
for objects only when you specifically need enumerable keys (considerObject.keys/entries
). - Keep one language style (English/Bangla/Banglish) per file.