w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Event object in Javascript, trouble finding information
Official W3c reccomendation clientX and clientY are the official event property handlers you are looking for. Although you might want to consider screenX and screenY too. Events (API) Events Creating, triggering events Event handlers Orientation and motion data Window Event X and Y property Explanation event.x and event.y, what are those? First of all, the x and y properties are not in all events. It is relative on the event triggered. Here is an example: document.body.onclick = function(){console.log(window.event.x)}; If you paste and execute that code in your browser's console, it will log you the x position of the cursor each time you click. Although taking a look at this example: document.body.onkeyup = function(){console.log(window.event.x)}; The console will

Categories : Javascript

Iterating through a javascript object and outputting certain information based upon criteria
use a simple template and loop though each item to generate your output: var data=[ { "SeatId": "29A", "passengerName": "Mr test1 test1", "sectorSequence": 1 }, { "SeatId": "22A", "passengerName": "Mr test1 test1", "sectorSequence": 2 }, { "SeatId": "29B", "passengerName": "Mrs test2 test2", "sectorSequence": 1 } ] function template(ob, str){ return str.replace(/{([ws.$]+?)}/g, function(j,a){ return ob[a]||""; } ); } strTemplate="First {passengerName} {sectorSequence} + {SeatId}"; out=$(data).map(function(i,item){ return template(item, strTemplate)}).toArray().join(" "); alert(out); /* result: First Mr test1 test1 1 + 29A First Mr test1 test1 2 + 22A First Mrs test2 test2 1

Categories : Javascript

Formating a javascript object not to display extra locale information
I know nothing about ms ajax templates. But assuming that the Date format behaves the same as in standard javascript, you can format your date manually. You can find more instructions here. If you have a lot of date formatting to do, you may want to check Moment.js

Categories : Javascript

JavaScript to store jquery result set information in an array
you can use $.each to iterate over the elements. var arr = []; $('.option').each(function() { arr.push( $(this).text() ); }); console.log(arr.join()); Check Fiddle You can also use the .map method var arr = $('.option').map(function () { return this.innerHTML }).get().join(); console.log(arr);

Categories : Javascript

Turning my php array into [object Object] json/JavaScript
You're alerting a string, so it seems that jQuery is not recognizing your response as JSON, and it is not being parsed. Try this: $.ajax({ url : "php/resource.php", data : { node_id: node_id }, dataType : "json" }).done(function(data) { alert(data); return callback(null, data); }).fail(function() { return callback("AJAX error"); });

Categories : PHP

How to deep copy an object in javascript as object not as array
Instead of var y = $.extend(true, [], x); Try var y = $.extend(true, {}, x); ^^--------- Empty object instead of empty Array

Categories : Javascript

How to merge two object of array lists in one array list in JavaScript
That's because a and b are not arrays. Assuming you can modify the json format (and you should as it's not valid) you could change it for this var a = [ {...}, {...}, {...} ]; var b = [ {...}, {...}, {...} ]; Then your code would work just fine

Categories : Javascript

JavaScript: assignment to an object within an array changes the value of all objects in the array
The problem is this: for( i = 0 ; i < len ; i++){ kddFlag.flagValue = data.flagValues[i]; this._children.push( new bugObject(kddFlag) ); you're creating 11 bugObject. But all of them have this._kddFlag pointing to the same kddFlag object, at the end of the loop kddFlag.flagValue is 1. To fix this, move your code into the loop. Like this: for( i = 0 ; i < len ; i++){ var kddFlag = {flagType : 'outlier', flagValue : -1}; kddFlag.flagType = data.flagType; kddFlag.flagValue = data.flagValues[i]; this._children.push( new bugObject(kddFlag) );

Categories : Javascript

Array vs. Object efficiency in JavaScript
It's not really a performance question at all, since arrays and objects work very differently (or are supposed to, at least). Arrays have a continuous index 0..n, while objects map arbitrary keys to arbitrary values. If you want to supply specific keys, the only choice is an object. If you don't care about the keys, an array it is. If you try to set arbitrary (numeric) keys on an array, you really have a performance loss, since behaviourally the array will fill in all indexes in-between: > foo = []; [] > foo[100] = 'a'; "a" > foo [undefined, undefined, undefined, ..., "a"] (Note that the array does not actually contain 99 undefined values, but it will behave this way since you're [supposed to be] iterating the array at some point.) The literals for both options should m

Categories : Javascript

javascript - how to get object from array, and use its methods?
You had several problems with your code. Associative array does not have .push() method so the following line failed: buffer_in.push ("whatever" + x); To fix this just declare plain array: var buffer_in = []; You tried to create instance of function called trans_helper which does not exist. The name is buffer instead, so fix would be: var trans_buffer = new buffer(buffer_in); Last but not least, you tried to call function in the "class" when it still did not exist yet. JavaScript does not "compile" functions in advance, when inside function it will go line by line. So in this line in your code: this.set_buffer (in_buffer); There was still no function called "set_buffer" in your class. To fix this, place the function declaration above, on top. Live test case.

Categories : Javascript

Javascript array index object
First of all, a bit of terminology: That is not an array, it is an object. Now that that's out of the way, I can't tell for certain what you're asking for. Are you looking for this, perhaps?: for( var i in assArray) { alert(i+": "+assArray[i]); // bad example, do something useful here }

Categories : Javascript

How to update an array of object in javascript
Since order doesn't really matter to you, better choice would be an object hash instead of an array. Something like { 'a':{name:'a', value: 'aa'} } This will let you search easily based on keys and you can update the hash. You can even employ above to your situation. Convert the array into a temporary object hash as above, do necessary changes, and convert back to an array. This will be more efficient as it will save you searches through the array. var output_array = []; for (var key in obj) { if (obj.hasOwnProperty(key)) { output_array.push(obj[key]); } }

Categories : Javascript

does object/array exist in javascript
If you're uncertain about the exisence of properties, try this helper function: function getProperty(root) { var l = arguments.length, i, undefined; for( i=1; i<l; i++) { if( typeof root[arguments[i]] == "undefined") return undefined; root = root[arguments[i]]; } return root; } You can then call it like this: var url = getProperty(item,'mediaGroups',0,'contents',0,'url'); As a more "haxy" way, you can try this: try {url = item.mediaGroups[0].contents[0].url;} catch(e) {url = undefined;}

Categories : Javascript

Javascript object array into a string?
You're missing a very cool feature of javascript. obj.Prop is the same as obj['Prop'] So, what you have to do is just use unit as key for the values.

Categories : Javascript

Javascript String to Object/Array
First, convert the data-users and data-userids into JSON (see http://www.php.net/manual/en/function.json-encode.php). That means the all quotes must be double quotes (""). <div class="container" data-users='["Chris","Johannes","test","lag@a.deaaas","lag@a.deaaa","lag@a.eaaa","lag@a.ea"]' data-userids='[1,2,3,12,13,15,16]'> Then you can get the data like this: var dataUsers = JSON.parse($('div.container').attr('data-users')) // dataUsers[0], dataUsers[1], dataUsers.length .... var dataUserIds = JSON.parse($('div.container').attr('data-userids'))

Categories : Javascript

Javascript sync object with an array
jQuery's map function should be what you need. var o = {'a':true,'b':false,'c':false,'d':true}; jQuery.map(o, function(val, idx){ if(val) return idx; }); if an Object changes, you could replace the old array with this: Still I don't think this is a pretty good solution..

Categories : Javascript

Pass an object into an array in JavaScript
It's not clear where you're trying to access the object, but the var in var savedRounds = []; means savedRounds is only locally scoped and only accessible inside roundList method. If you want to access savedRounds outside the roundList method, then declare savedRounds = []; outside the roundList method or return it from the method so something else can access it.

Categories : Javascript

Get max and min of object values from JavaScript array
Use this example var lowest = Number.POSITIVE_INFINITY; var highest = Number.NEGATIVE_INFINITY; var tmp; for (var i=myArray.length-1; i>=0; i--) { tmp = myArray[i].Cost; if (tmp < lowest) lowest = tmp; if (tmp > highest) highest = tmp; } console.log(highest, lowest);

Categories : Javascript

System.NullReferenceException' occurred in WindowsApplication1.exe Additional information: Object reference not set to an instance of an object
You are only declaring the variable ds. You should create an instance, before you can use the methods. Dim ds As DataSet should be Dim ds As New DataSet or Dim ds As DataSet ds = New DataSet

Categories : SQL

IE8 Array.prototype.slice: 'this' is not a JavaScript object
When you call: this.menuItems = this.el.querySelectorAll( '.cbp-hsmenu > li' ); the object assigned to menuItems is a static NodeList, which is a host object. Then when you do: Array.prototype.slice.call( this.menuItems ) you are calling a built–in method with a host object as this. In IE 8 and lower (and probably lots of other older browsers), you can't do that (there is no specification that says you should, though modern browsers let you). The simple solution is to convert menuItems to an array using some other method than call, or to add a shim for Array.prototype.forEach and use CrazyTrain's suggestion: Array.prototype.forEach.call(this.menuItems, func...) because in browsers without a built–in forEach, it will be a native method and work just fine. But for robust cod

Categories : Javascript

Looping through json object that has an array with javascript
You just need to append it to the string, instead of reassigning the variable again and again: var theimages; var html = '<ul>'; for(var i=0; i < data.length; i++) { var item = data[i]; var obj = { title:item.title, image:item.image }; for(j=0; j < item.image.length; j++) { theimages += '<li>' + item.image[j] + '</li>'; } html += '<li>' + item.title + '<ul>'; html += theimages; html += '</ul></li>'; } html += '</ul>'; console.log(html);

Categories : Javascript

Reading data object of array in javascript
You are accessing the JSON like you would a dictionary or array. JSON works differently. Let's assume we are storing our JSON in a variable we call data, like so: var data = { "store": [ { "skey": "asdsad123das", "name": "Store1" }, { "skey": "3308d976d2647659f130d09593be845a", "name": "joji store" } ], "manager": [ { "mkey": "asdsad123das", "name": "manager 1" }, { "mkey": "asdsad123da2", "name": "Manager 2" }, { "mkey": "asdsad123da3", "name": "Manager 3" } ] }; Then we can access specific keys like so: data.store[0].skey // skey of first element of store array of data object If you want to iterate over the data in data, you can do: for (index in data.store) { console.log(data.store[index]); // prints whole object

Categories : Javascript

How can I convert a json object to an array in javascript
You can check if the object is an array using this: Object.prototype.toString.call( response.renditions.rendition ) === '[object Array]' And you can simplify the conversion to an array -- just wrap it as an array using x = [x]: if (Object.prototype.toString.call( response.renditions.rendition ) !== '[object Array]') { response.renditions.rendition = [response.renditions.rendition]; } Fiddle demo.

Categories : Javascript

Can't send javascript object array to new page
As you didn't state the structure of the js variable documents I am assuming it is just an array of UploadFiles. Something along the lines of: var documents = []; for (var i = 0; i < 10; i++) { var d = { id: i, title: i.toString() }; documents.push(d); } Which you then taking and sending via ajax. This will not work as documents do not have a container so the URL for the GET will look something like /Document/Review?undefined=&undefined=&undefined=&undefined=& By changing it to var data = { model: documents }; $('.js_btn-review').click(function () { $.ajax({ url: '/Home/Review', data: data,

Categories : Javascript

javascript: check if complex object is in array
When you do this: queryParamCache[cacheObj] you're actually doing this: queryParamCache[String(cacheObj)] which is (on generic objects) queryParamCache["[object Object]"] regardless of what's in cacheObj. Consider: Live Copy | Live Source var a = {foo: "bar"}; var b = {bar: "charlie"}; var cache = {}; cache[a] = "Hi there"; console.log(cache[b]); // "Hi there" Both a and b get turned into the string "[object Object]". How do I achieve what I want ? If your goal is to have queryParamCache be a store of values that you can look up by using an object, you'll have to define a mechanism for turning that object into a string. Property names (keys) in JavaScript objects are always (for now) strings. One way you can do that is to give your objects a different toString method,

Categories : Javascript

Remove object elements from array in javascript
You can use Array.filter and Array.forEach to filter out nodes with 0 weight. First, define a predicate: var keepNode = function(node) { return !(node.weight == 0 && node.hasOwnProperty("nodes")); }; Then a function to clean a node of unwanted children and then recurse on the remaining children: function clean(tree) { if (tree.nodes) { tree.nodes = tree.nodes.filter(keepNode); tree.nodes.forEach(clean); } } Finally, process the entire data structure: clean(nodeset); There's almost certainly a more elegant way that recurses as it filters, but this should do the job. EDIT (because I didn't notice the IE8 tag) For IE8 (which doesn't support filter), you have a couple of choices. You can use the ES5 shim package that adds most EcmaScript functio

Categories : Javascript

basic javascript - referring to an object in an array
prop actually is the name of the object's property (=key), not the property itself. It's a plain string ("bill") and not the actual object friends.bill (/a reference to it). This is also the reason, why you write friends[prop] // prop gets evaluated here, it's value is the identifier instead of friends.prop // prop is treated as the identifier here Example: var friends = { bill: { ... } } for (var prop in friends) { // prop == "bill"; friends[prop] == friends.bill } Actually, this is similar to (the new) Object.keys(friends) which returns you an array of all property names of the object you could then iterate on (which perhaps is a bit more intuitive for people coming from other languages). EDIT: One important note! Unlike Object.keys(), for in lists all prop

Categories : Javascript

JavaScript pushing an object in an array is what - by reference or value?
Objects are ALWAYS passed by reference. When you write abc = { a: 10000, b: 20000 }, what you are overwriting is the variable abc, which was pointing to the old object, but is now pointing to the new one.

Categories : Javascript

Get object names from a array of objects in javascript
Try with: function givemepleasethenameoftheobject(index, data) { var i = 0; for ( var k in data ) { if ( index == i++ ) { return k; } } } var result = givemepleasethenameoftheobject(2, Statistics);

Categories : Javascript

Merge Objects in a JavaScript Array to object
Loop through the array, use a for-in loop on each object, and for entries where typeof value === "number", sum them up. Presumably do something useful when they aren't numbers, but you haven't said what. :-) Sorry, missed the jQuery tag. It can be shorter with jQuery's each: var dest = {}; $.each(source, function(index, entry) { $.each(entry, function(key, value) { if (typeof value === "number") { dest[key] = key in dest ? dest[key] + value : value; } else { // do something useful with non-numbers } }); }); each will loop through the array elements if you give it an array, or through the properties of an object if you give it a non-array object. So in the above, the outer each loops through your array, and the inner each

Categories : Javascript

How do I apply changes to a data object within a JavaScript array?
function UpdateValues(passedId, prop, newValue) { var thisData = {}; for ( var i = 0; i < dataContainer.length; i++ ) { thisData = dataContainer[i]; if (thisData.id == passedId) { thisData[prop] = newValue; } } } //Change qty to 99999 for object with index of 1 UpdateValues(1, "qty", 99999); I've added a fiddle that prints out the result as well: http://jsfiddle.net/4UH9e/

Categories : Javascript

Why can you not return an object to Javascript's Array.map() and it map it properly?
The problem is, that you return "paragraph" in the callback function of waterfall. So the function sentenceObjs returns nothing, or undefined. You need to pass in a callback function to sentenceObjs and call async.map instead of Array.map: self.parseBodySections = function(dom, cb) { async.map(dom, self.sentenceObjs, function(err, bodyJSON) { console.log(bodyJSON); // prints: [ undefined, undefined, undefined, undefined, undefined ] return cb(null, bodyJSON); }); }; self.sentenceObjs = function(section, cb) { var paragraphToTextAndLinks = function(cb) { return self.paragraphToTextAndLinks(section.children, function(err, paragraphText, links) { if (err) { return cb(err); } return cb(null, paragraphText, links); }); }; return async.wat

Categories : Javascript

Convert array(object?) to string in javascript
And it's true, array doesn't have any split method. You're messing Join and Split methods, one belong to array, the other to string functions. What you want is: var splitText = optionTextString.join(",");

Categories : Javascript

Convert javascript array to java object
Short answer: Yes. ;-) Long answer: Considering how similar Java and JavaScript seem to be, this is surprisingly hard. First of all, your input isn't in JSON format (for JSON, strings must use " quotes), so you can't use one of the many JSON parsing libraries like gson or jackson. So the next option would be to use a JavaScript interpreter like Rhino, call evaluateString() and examine the result. This gives you an JavaScript array instance which will feel very odd to use from a Java perspective - remember, JavaScript arrays are actually more like hash maps than plain Java arrays plus some JavaScript oddities. If you want to get value 5 from such an array, you can use array.get(5, array); Last option is to write your own parser.

Categories : Java

C++: Propagation of information from child object to parent object
Giving the Employee a pointer to its Supervisor is the traditional method for arranging for callbacks or progress reports. (That's your solution number three.) It's only one pointer. If you have enough employees that you're worried about the memory use (i.e. a few thousand of them), you can reduce the size by using a smaller handle rather than a pointer. That is, something like typedef uint8_t SupervisorHandle; class Employee { private: SupervisorHandle s; Supervisor& getSupervisor() { return startup.getSupervisor(s); } // ... }; If you place the handle sensibly around your other fields, it need only take a byte, and now you can have up to 256 supervisors. But this comes at the cost of flexibility: it ties you to the static Corporation instance, and add

Categories : C++

how to create Object key & value in JavaScript dynamically from array string
I would go like this : var value=[["xyz","01","abc"],["def","02","ghi"]]; // notice it's an array of array instead of an array of objects var elements = []; for (var i = 0; i< value.length; i++) { var elem = new Object(); for (var j=0; j< key.length; j++) { elem[key[j]] = value[i][j]; } elements.push(elem); }

Categories : Javascript

Simple Javascript game: Possible object array error
The problem is that function bolt(facing,playerX,playerY){ does not create a new bolt, it just sets variables in the same spot as before: function bolt(facing,playerX,playerY){ //The bolt object is shot from the player's current position this.facingLeft=facing; //The direction at which the bolt moves, if left, true ... -Because you do not call bolt on a new object, you call it from the same place every time, all of the variables you set under this keep getting overriden over and over again.

Categories : Javascript

unable to get array length of object property in javascript
The below line defines the length of your array which is 2, however you have not pushed any item in your array the length will show 2, which is absolutely correct..! questions_completed:new Array(2)

Categories : Javascript

Filter Array Before Push JSON Object to Javascript
This would check for previous value with the current value and skip it if they are same dataJSON2 = []; var lastVal = parsed2 && parsed2[0]; for (var i = 1; i < parsed2.length; i++) { if (lastVal !== parsed2[i].value) { dataJSON2.push([(parsed2[i].timestamp), parseFloat(parsed2[i].value)]); lastVal = parsed2[i]; } }

Categories : Javascript

access javascript array element by JSON object key
I know that's not right and am hoping that there is a solution without looping through the result set every time? No, you're gonna have to loop and find the appropriate value which meets your criteria. Alternatively you could use the filter method: var filteredZips = Zips.filter(function(element) { return element.Zip == 92880; }); if (filteredZips.length > 0) { // we have found a corresponding element var count = filteredZips[0].count; } If you had designed your object in a different manner: var zips = {"92880": 1, "91710": 3, "92672": 0 }; then you could have directly accessed the Count: var count = zips["92880"];

Categories : Javascript



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.