--- title: Set.prototype.delete() slug: Web/JavaScript/Reference/Global_Objects/Set/delete tags: - ECMAScript 2015 - JavaScript - Method - Prototype - Reference - set translation_of: Web/JavaScript/Reference/Global_Objects/Set/delete ---
delete()
메서드는 지정한 요소를 Set
객체에서 제거합니다.
mySet.delete(value);
value
Set
객체에서 제거할 요소의 값.요소를 제거했으면 true
, 아니면 false
.
delete()
사용하기var mySet = new Set(); mySet.add('foo'); mySet.delete('bar'); // Returns false. No "bar" element found to be deleted. mySet.delete('foo'); // Returns true. Successfully removed. mySet.has('foo'); // Returns false. The "foo" element is no longer present.
다음 예제는 Set
에서 객체를 제거하는 방법을 보입니다.
var setObj = new Set(); // Create a New Set. setObj.add({x: 10, y: 20}); // Add object in the set. setObj.add({x: 20, y: 30}); // Add object in the set. // Delete any point with `x > 10`. setObj.forEach(function(point){ if(point.x > 10){ setObj.delete(point) } })
Specification | Status | Comment |
---|---|---|
{{SpecName('ES2015', '#sec-set.prototype.delete', 'Set.prototype.delete')}} | {{Spec2('ES2015')}} | Initial definition. |
{{SpecName('ESDraft', '#sec-set.prototype.delete', 'Set.prototype.delete')}} | {{Spec2('ESDraft')}} |
{{Compat("javascript.builtins.Set.delete")}}