jsÔõôɾ³ýmapÖеÄÊý¾Ý
Òª´Ó javascript µÄ map ÖÐɾ³ýÊý¾Ý£¬¿ÉÒÔʹÓà delete ÒªÁì¡£Óï·¨£ºmap.delete(key)£¬ÆäÖÐ map ÊÇ map ¹¤¾ß£¬key ÊÇҪɾ³ýµÄ¼ü¡£Ê¾Àý£ºconst mymap = new map(); mymap.set(‘name’, ‘john doe’); mymap.set(‘age’, 30); mymap.delete(‘age’); console.log(mymap.has(‘age’)); // false
ÔõÑùʹÓà JavaScript ´Ó Map ÖÐɾ³ýÊý¾Ý
JavaScript ÖÐµÄ Map Êý¾Ý½á¹¹ÔÊÐíÄã´æ´¢¼üÖµ¶ÔµÄÜöÝÍ¡£Òª´Ó Map ÖÐɾ³ýÊý¾Ý£¬¿ÉÒÔʹÓà delete ÒªÁì¡£
Óï·¨£º
map.delete(key);
µÇ¼ºó¸´ÖÆ
ÆäÖУº
map ÊÇÒª¾ÙÐÐɾ³ý²Ù×÷µÄ Map ¹¤¾ß¡£
key ÊÇҪɾ³ýµÄ¼ü¡£
ʾÀý£º
// ½¨ÉèÒ»¸ö Map const myMap = new Map(); // Ìí¼Ó¼üÖµ¶Ô myMap.set('name', 'John Doe'); myMap.set('age', 30); // ʹÓà delete ÒªÁìɾ³ý¼üÖµ¶Ô myMap.delete('age'); // ¼ì²é¼üÊÇ·ñÒÑɾ³ý console.log(myMap.has('age')); // false
µÇ¼ºó¸´ÖÆ
×¢ÖØ£º
delete ÒªÁì²»»á·µ»ØÈκÎÖµ¡£
ÈôÊÇҪɾ³ýµÄ¼ü²»±£´æ£¬delete ÒªÁ콫·µ»Ø false¡£
ÈôÊÇÒªÇå¿ÕÕû¸ö Map£¬¿ÉÒÔʹÓà clear ÒªÁì¡£
ÒÔÉϾÍÊÇjsÔõôɾ³ýmapÖеÄÊý¾ÝµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡