JavaScript Object Id

If you want to lookup/associate an object with a unique identifier without modifying the underlying object, you can use a WeakMap: // Note that object must be an object or array, // NOT a primitive value like string, number, etc. var objIdMap=new WeakMap, objectCount = 0; function objectId(object){ if (!objIdMap.has(object)) objIdMap.set(object,++objectCount); return objIdMap.get(object); } var … Read more