ধরি আমাদের Setটি নিচের মতো:
var name = new Set(['John', 'David', 'Bob', 'Mike']);
Set কে Object-এ রূপান্তর করতে জাভাস্ক্রিপ্টে Object.assign() ব্যবহার করা হয়:
var setToObject = Object.assign({}, ...Array.from(name, value => ({ [value]: 'not assigned' })));
উদাহরণ
নিচের কোডটি অনুসরণ করুন:
var name = new Set(['John', 'David', 'Bob', 'Mike']);
var setToObject = Object.assign({}, ...Array.from(name, value => ({ [value]: 'not assigned' })));
console.log("The Set result=");
console.log(name);
console.log("The Object result=");
console.log(setToObject);
প্রোগ্রামটি রান করতে নিচের কমান্ডটি ব্যবহার করুন:
node fileName.js
এখানে ফাইলের নাম হলো demo260.js।
আউটপুট
কনসোলে নিচের আউটপুটটি দেখাবে:
PS C:\Users\Amit\javascript-code> node demo260.js
The Set result= Set { 'John', 'David', 'Bob', 'Mike' }
The Object result= {
John: 'not assigned',
David: 'not assigned',
Bob: 'not assigned',
Mike: 'not assigned'
}