object

Javascript if a value exists in an object?

感情迁移 提交于 2020-08-23 12:16:31
问题 ive got an object: var car = { company: "Honda", year: "2011", Model: "Brio" } I was wondering if there exists an inherited method (is that the right phrase?) to check if a value exists inside a given object, somewhat like x.hasOwnProperty , or if (x in car) . Or, should I write my own. I've done a few google searches, but they all either lead to hasOwnProperty or to check if a value exists inside an array. Editing to please all the people in the comments: There are two use cases i could

How to make a short beep in javascript that can be called *repeatedly* on a page?

假装没事ソ 提交于 2020-08-22 05:11:10
问题 This is like the question at: Sound effects in JavaScript / HTML5 but I'm just seeking a specific answer to the issue of repeatability. The above question and other similar ones have helpful answers to use the following javascript: function beep1() { var snd = new Audio("file.wav"); // buffers automatically when created snd.play(); } or even more self-contained, you can now include a wav in-line, such as: function beep2() { var snd = new Audio("data:audio/wav;base64,/

Set array of object to null in C++

不问归期 提交于 2020-08-21 17:24:53
问题 Suppose I have an array of objects of type Foo in C++: Foo array[10]; In Java, I can set an object in this array to null simply by: array[0] = null //the first one How can I do this in C++? 回答1: Use pointers instead: Foo *array[10]; // Dynamically allocate the memory for the element in `array[0]` array[0] = new Foo(); array[1] = new Foo(); ... // Make sure you free the memory before setting // the array element to point to null delete array[1]; delete array[0]; // Set the pointer in `array[0]