forInObjectDelete.js 710 B

123456789101112131415161718192021222324252627
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. WScript.Echo("Delete current element");
  6. var x = { a: 2, b: 3 };
  7. for(var i in x)
  8. {
  9. if(x[i] == 2)
  10. delete x[i];
  11. else
  12. WScript.Echo(x[i]);
  13. }
  14. WScript.Echo("Delete former element");
  15. var o = { a: 2, b: 3 }
  16. var n = 0;
  17. for(var i in o)
  18. {
  19. if(n++ == 1)
  20. delete o.a;
  21. WScript.Echo(i);
  22. }