lang stringclasses 4
values | desc stringlengths 2 8.98k | code stringlengths 7 36.2k | title stringlengths 12 162 |
|---|---|---|---|
JS | So , a bug in a piece of javascript revolved around code similar to : In the larger system IE complained `` Expected ' ; ' `` . In the small scale example IE simply caused a warning about blocking ActiveX controls . Obviously , `` // @ '' has some context to activeX controls in IE . I was unable to find this as searchi... | < script > ( function ( ) { if ( true ) { // @ todo : do we need to set total or -- ? alert ( 'hello ? ' ) ; } } ) ( ) ; < /script > | What does IE use // @ in javascript for ? |
JS | The following code is presented , in the book Head First jQuery.It gets called with this line.The observed behaviour is that the lightning fades in and out once , waits 3 seconds , fades in and out again , and then continues to fade in and out . Firebug shows no javascript errors.I understand why I see what I see . I t... | function lightning_one ( t ) { $ ( `` # lightning1 '' ) .fadeIn ( 250 ) .fadeOut ( 250 ) ; setTimeout ( `` lightning_one ( ) '' , t ) ; } ; // end lightning_one lightning_one ( 3000 ) ; setTimeout ( `` lightning_one ( ) '' , t ) ; // nothing in the brackets setTimeout ( `` lightning_one ( t ) '' , t ) ; // t is in the ... | Variable Not Defined , Sometimes |
JS | Edit : This is using Google Chrome 36I was messing around with html5 canvas , generating points randomly distributed inside a cube and projecting that onto a 2D canvas . Surprisingly , the results do n't look very symmetric at all , and I suspect that Javascript 's Math.random ( ) is letting me down.Can anyone tell me ... | var ctx = canvas.getContext ( '2d ' ) ; for ( var i = 0 ; i < 10000000 ; i++ ) { var x = Math.random ( ) *2-1 , y = Math.random ( ) *2-1 , z = 2+Math.random ( ) *2-1 ; x = ( .5 + .5*x/z ) * canvas.width ; y = ( .5 + .5*y/z ) * canvas.height ; ctx.fillRect ( Math.floor ( x ) , Math.floor ( y ) , 1 , 1 ) ; } | Why does this random ( ) distribution look asymmetric ? |
JS | For example , I have codes ( coffeescript ) like this : This may be chained by other lodash method later . Meanwhile , its value may be necessary to be extracted . I was justing wonder whether it will cache the result . I did n't find how it is implemented in its documentation..Will it be calculated once or twice for :... | sortedLatLng = _ ( w ) .sortBy ( x ) - > x.time .map ( x ) - > [ x.longitude , x.latitude ] .uniq ( ( x ) - > x [ 0 ] .toFixed ( 3 ) + `` , '' + x [ 1 ] .toFixed ( 3 ) ) # keep three decimal to merge nearby pointsconsole.log ( sortedLatLng.value ( ) ) myFunction1 ( sortedLatLng.value ( ) ) myFunction2 ( sortedLatLng.va... | In lodash.js , will it cache the result for ` .value ( ) ` method ? |
JS | I have a value in my faunadb database that i want to increase by one when clicking a button . I am not sure how to do thati tried it with this : and triggered it with thismy serverside code is this : i expected this to increment my value in the database by 1 but in reality i get an error that looks like this : POST htt... | const change = ( data ) = > { return fetch ( ` /.netlify/functions/todos-update ` , { body : JSON.stringify ( data ) , method : 'POST ' } ) .then ( response = > { return response.json ( ) } ) } var dataa = document.getElementById ( 'amount ' ) .innerHTMLchange ( ( `` value : `` + dataa ) ) exports.handler = ( event , c... | How to increment value in faunadb ? Using javascript and serverside functions |
JS | I 'm currently working with two data models , where Foo has a `` toMany '' property of type Bars . I 'm now trying to create two select boxes where when the first populated with Foo 's is picked , it refines the second listing only the Bars associated with that foo.JSFiddle Here : http : //jsfiddle.net/drew/6jLCy/Code ... | App = Em.Application.create ( ) ; App.store = DS.Store.create ( { revision : 7 , adapter : DS.fixtureAdapter } ) ; /*************************** Models**************************/App.Foo = DS.Model.extend ( { bars : DS.hasMany ( 'App.Bar ' ) , title : DS.attr ( 'string ' ) } ) ; App.Bar = DS.Model.extend ( { foos : DS.ha... | EmberJS Binding Content Between Controllers |
JS | I want to iterate over the elements of an array and if a condition is true I want to create a new array . Example : I have an array called Messages whose elements are objects and I want to check if the id attribute equals 5 . If yes create a new array only consisting of this object.I want my result to be : | messages = [ { `` id '' : 10 , `` body '' : `` hello ! `` } , { `` id '' : 21 , `` body '' : `` hola ! `` } , { `` id '' : 5 , `` body '' : `` ciao ! `` } ] ; var message5 = [ ] ; var dataObj = { } ; $ .each ( messages , function ( index , value ) { if ( value.id == 5 ) { dataObj [ index ] = value ; } } ) ; message5.pu... | Use conditional inside $ .each function to create array |
JS | I 'm optimizing the compiler of a language to JavaScript , and found a very interesting , if not frustrating , case : It takes 2.3s to complete on my machine [ 1 ] . But if I make a very small change : It completes in 1.1s . Notice the only difference is the addition of an immediately invoked lambda , ( ( ) = > ... ) (... | function add ( n , m ) { return n === 0 ? m : add ( n - 1 , m ) + 1 ; } ; var s = 0 ; for ( var i = 0 ; i < 100000 ; ++i ) { s += add ( 4000 , 4000 ) ; } console.log ( s ) ; function add ( n , m ) { return ( ( ) = > n === 0 ? m : add ( n - 1 , m ) + 1 ) ( ) ; } ; var s = 0 ; for ( var i = 0 ; i < 100000 ; ++i ) { s += ... | Why does adding in an immediately invoked lambda make my JavaScript code 2x faster ? |
JS | I ca n't understand why window is under self and self is under window object . if you go to dev-tools or Firebug and write window you got DOM window object that self is under this object . The weird part is that window is under self again ! You can writeand still you get window object ! How ? ! | window.self.window.self.window.self.window.self.window.self.window.self.window.self.window.self.window.self.window.self.window.self.window.self.window.self.window.self.window.self.window.self.window.self.window.self.window.self.window.self.window.self.window.self.window.self.window.self.window.self.window.self.window.s... | Weird self object in window object |
JS | When displayed in the console , the result I get between the p tags contains the space in index 3 , which is correct . But when displayed on page I get `` _ _ _ _ '' . The space in index 3 is not visible . Here 's the CodePen . How can I get the space between the underscores to be displayed on the page ? I CANT EVEN GE... | < html > < p id= '' myid '' > < /p > < script > var myArray = [ `` _ '' , `` _ '' , `` `` , `` _ '' , `` _ '' ] ; var hiddenWord = document.getElementById ( 'myid ' ) ; var temp ; function newGame ( ) { temp = myArray.join ( `` `` ) ; hiddenWord.innerHTML = temp ; } newGame ( ) ; console.log ( `` temp variable '' , tem... | My array contains a blank space [ `` `` ] . When I .join the space with underscores , the space element in the resulting string is not visible in the html |
JS | I am new to React and I am trying to return a generic button component . The button is supposed to show one of three different icons , either `` DeleteIcon '' , `` AddIcon '' or `` EditIcon '' . The specified button type is specified as `` buttonType '' in the input of the IconButton function.However I keep getting `` ... | import React from 'react ' ; import Button from ' @ material-ui/core/Button ' ; import DeleteIcon from ' @ material-ui/icons/Delete ' ; import AddIcon from ' @ material-ui/icons/Add ' ; import EditIcon from ' @ material-ui/icons/Edit ' ; export default function IconButton ( { handler , text , color , fill , buttonType ... | How to solve element type invalid error in react |
JS | I just took a look to that : http : //jsperf.com/array-destroy/32I do n't understand how the first one : Can be slower than : Someone could link/explain why ? | arr.length = 0 ; while ( arr.length > 0 ) { arr.shift ( ) ; } | Javascript perf to clean an array |
JS | Identifying which objects are which is complicated in JavaScript , and figuring out which objects are arrays has something of a hacky solution . Fortunately , it manages to work in both of the following cases : Great , no [ object Object ] in sight ! Sadly , this method still manages to fail with this : This is frustra... | Object.prototype.toString.call ( [ ] ) ; // [ object Array ] Object.prototype.toString.call ( new Array ( ) ) ; // [ object Array ] var arr = Object.create ( Array.prototype ) ; Object.prototype.toString.call ( arr ) ; // [ object Object ] function inherits ( obj , proto ) { while ( obj ! = null ) { if ( obj == proto )... | Is it possible to determine if an object created with Object.create inherits from Array in JavaScript ? |
JS | I 'm trying update a table cell using jeditable so when the user clicks the cell it becomes editable . Below code works fine : But when I try to edit a cell that has been dynamically added to the table using jQuery : The event does not fire . How can this be fixed ? I think I may have to use the .on function ? | $ ( `` .click '' ) .editable ( `` http : //www.appelsiini.net/projects/jeditable/php/echo.php '' , { indicator : `` < img src='img/indicator.gif ' > '' , tooltip : `` Click to edit ... '' , style : `` inherit '' } ) ; < b class= '' click '' style= '' display : inline '' > Click me if you dare ! < /b > < / > $ ( `` # ro... | How to add dynamic click handler to jeditable |
JS | In what way to get the function caller of ajaxError event produced for js error reporting ? I have built a js error repo app with jQuery and I can handle normal js errors occurred globally , but I have problems on ajax errors.I can get the line number of error when it is a normal error ! I tried to catch them with one ... | const error_log_url = '/log ' ; const errorPost = function ( data ) { $ .ajax ( { url : error_log_url , type : 'post ' , data : data , success : function ( res ) { console.log ( res ) } , error : function ( res ) { console.log ( res ) } } ) } window.addEventListener ( 'error ' , function ( e ) { let params = { message ... | How to jQuery Ajax Error Catch and Report |
JS | What is the difference between the followingand thisWhich of these should be used when ? | response.status ( 200 ) .send ( 'Hello World ! ' ) ; response.writeHead ( 200 , { 'content-type ' : 'application/json ' } ) ; response.end ( 'Hello World ! ' ) ; | Difference between response.status and response.writeHead ? |
JS | Possible Duplicate : What it the significance of the Javascript constructor property ? In the Javascript docs at developer.mozilla.org , on the topic of inheritance there 's an exampleI wonder why should I update the prototype 's constructor property here ? | // inherit PersonStudent.prototype = new Person ( ) ; // correct the constructor pointer because it points to PersonStudent.prototype.constructor = Student ; | When is it necessary to set the 'prototype.constructor ' property of a class in Javascript ? |
JS | Inside a callback I build an object I build to send out in my Express app : If I get a different response than what I 'm used to I get a fatal can not find 'property ' of undefined error that crashes my server caused by these : data.actions [ 1 ] .causes [ 0 ] .shortDescription.I was wondering what to do about it and I... | this.response = { owner : data.actions [ 1 ] .causes [ 0 ] .shortDescription , build_version : data.actions [ 0 ] .parameters [ 0 ] .value , branch_to_merge : data.actions [ 0 ] .parameters [ 1 ] .value , jira_tickets : data.actions [ 0 ] .parameters [ 2 ] .value , build_description : data.actions [ 0 ] .parameters [ 3... | Using a try catch around an object literal |
JS | Is the following HTML/Javascript valid ( strict ) when Javascript is enabled ? Is the id in the noscipt tag ignored ? | < body > < noscript > < div id= '' test '' > < /div > < /noscript > < script type= '' text/Javascript '' > var el = document.createElement ( 'span ' ) ; el.id = 'test ' ; document.body.appendChild ( el ) ; < /script > < /body > | Duplicate id within noscript |
JS | Reading through some code , I came across the use of ! 0 and ! 1 . I realize that these are shorter ways of writing true and false.This of course save a few bytes , but is there some other reason to use it ? Is there a name for this way of writing it ? | ! 0 === true ! 1 === false | Is ! 0 and ! 1 something more than a shorthand for true/false ? |
JS | I 'm trying to process a complete function in an ajax call . If the value is undefined , I want cast a var as an empty string . Otherwise , I would like to capture the value into a string array.The problem is I 'm entering the if statement , even when logging the value of the variable in question returns as undefined .... | completefunc : function ( xData , Status ) { $ ( xData.responseXML ) .SPFilterNode ( `` z : row '' ) .each ( function ( ) { if ( typeof $ ( this ) .attr ( `` ows_Products '' ) ! == undefined ) { console.log ( $ ( this ) .attr ( `` ows_Products '' ) ) ; arr = $ ( this ) .attr ( `` ows_Products '' ) .split ( ' , ' ) ; } ... | Having trouble with undefined ! == undefined |
JS | I stream audio over rtc and want to mute and unmute the audio.This works ... but no gain control : This works on chrome but NOT on Firefox ( with gain control ) I get no error and i hear no voice . When I send the gainNode to context.destination i can hear myself.I think `` context.createMediaStreamSource ( stream ) ''... | function ( stream ) { /* getUserMedia stream */ console.log ( `` Access granted to audio/video '' ) ; peer_connection.addStream ( stream ) ; } function ( stream ) { /* getUserMedia stream */ console.log ( `` Access granted to audio/video '' ) ; var microphone = context.createMediaStreamSource ( stream ) ; gainNode = co... | Firefox createMediaStreamDestination bug using rtc ? |
JS | I just found out the hard way that naming your variable arguments is a bad idea . Output : [ ] It turns out that arguments is `` a local variable available within all functions '' so in each new execution context , arguments is shadowed.My question is : Are there any other such treacherous names which , like arguments ... | var arguments = 5 ; ( function ( ) { console.log ( arguments ) ; } ) ( ) ; | JavaScript identifiers not to use |
JS | I have this dataset which has ellipses , more specifically ellipse `` envelopes . '' I was wondering if someone had advice on how I could draw these on a D3 map . I already have a map setup with mercator projection . This stackoverflow answer has a createEllipse function which got me close , but I want to make sure I a... | const margin = { top:0 , right:0 , bottom:0 , left:0 } , width = 1000 - margin.left - margin.right , height = 800 - margin.top - margin.bottom ; const svg = d3.select ( 'body ' ) .append ( 'svg ' ) .attr ( 'width ' , '100 % ' ) .attr ( 'height ' , '100 % ' ) .attr ( 'viewBox ' , ` 0 0 $ { width + margin.left + margin.r... | Creating D3 map of ellipse envelope data |
JS | When I click a button the text will change every time . For example when I go to the page it shows 'Close ' . If I click that button and it 's value will change to 'Open ' . It happens in another way also . If I click the 'Open ' then it changes to close.However the problem is if the button is in 'Open ' state and if I... | function changeStatus ( ) { console.log ( `` Hi '' ) ; var val = document.getElementById ( `` openClose '' ) .value ; $ .ajax ( { type : 'POST ' , url : '/change/me ' , data : { 'val ' : val } , success : function ( result ) { alert ( `` The text has been changed '' ) ; } } ) } $ ( `` .changeme '' ) .click ( function (... | After refreshing a button , text is changing in jquery |
JS | I have a base service which looks like this : and then I have a few services which `` inherit '' this service , like this : I thought that this was working fine . But I have this page that calls all 3 services ( ImageService , LogoService and PlayerTextService ) sequentially . On the first view of the page everything i... | .service ( 'BaseImageService ' , [ ' $ q ' , 'ApiHandler ' , 'UploadService ' , function ( $ q , api , uploadService ) { // Get our api path var apiPath = 'logos ' ; // Creates our logo var _createLogo = function ( model ) { // Handle our uploads return _handleUploads ( model ) .then ( function ( ) { // Create our logo... | AngularJS service inheritance issues |
JS | So I 'm running into a bit of a problem.I 've been trying to find a way to make the width of an input element fit the content . I kept making progress but then for whatever reason that method did n't work . So now I 'm on here looking for help . I 'll share the methods that I 've attempted that did n't end up working f... | var ctx = document.querySelector ( 'canvas ' ) .getContext ( '2d ' ) ; var input = document.querySelector ( 'input ' ) ; ctx.font = window.getComputedStyle ( input ) .getPropertyValue ( 'font-size ' ) + ' '+window.getComputedStyle ( input ) .getPropertyValue ( 'font-family ' ) ; input.addEventListener ( 'keyup ' , ( ) ... | Input width fit to content |
JS | I have a very specific question and I am not sure you can do what I want with css . For what I 've seen on other posts , this might be out limits , but I thought I 'd ask in case there are some css geniuses out there.I want to achieve a very specific behaviour.I have a column of text and some words in that column are h... | < p > text < span id= '' clickable '' class= '' link '' > highlighted text < /span > . < div class= '' closed '' > < video id= '' video '' width= '' 100 % '' > < source src= '' myVideo.mp4 '' type= '' video/mp4 '' > < /video > < /div > text < /p > .closed { overflow : hidden ; height : 0px ; transition-property : all ;... | How to get text and video to flow together |
JS | I have two statements like this . Why do they both evaluate to false ? If [ ] == true is false should n't ! [ ] == true result to true ? | console.log ( [ ] == true ) console.log ( ! [ ] == true ) | Why do both `` [ ] == true '' and `` ! [ ] == true '' evaluate to false ? |
JS | I am basing a website on an old tutorial , which uses 3 external js files . I am not able to recreate this using nuxtjs.First , I tried to include the js files before the tag.nuxt.config.jsThis works on initial page load . However , as soon as I change the page , the js files are ignored.After some research , I tried t... | head : { script : [ { src : 'js/imagesloaded.pkgd.min.js ' , type : 'text/javascript ' , body : true , defer : true } , { src : 'js/TweenMax.min.js ' , type : 'text/javascript ' , body : true , defer : true } , { src : 'js/demo.js ' , type : 'text/javascript ' , body : true , defer : true } ] } , plugins : [ { src : ``... | External Javascript files in nuxtjs |
JS | Am messing around with prototypes to get a better understanding of how they work . I ca n't work out why I ca n't call hideHeader , whereas I can access a variable ( this.header.el ) | function App ( ) { this.init ( ) ; this.el = document.getElementById ( 'box ' ) ; } App.prototype.init = function ( ) { document.write ( 'hello world ' ) ; this.header = new Header ( ) ; this.header.hideHeader ( ) ; this.header.el.style.display = 'none ' ; } ; new App ( ) ; function Header ( ) { this.el = document.getE... | Understanding how JavaScript Prototypes work |
JS | I tried to write a javascript code with a memory leak in order to work with the profiler in Chrome . However , it seems the profiler is n't showing what it should be.Here 's my code : You can see when I click on start button a new object Leaker is created.And when I click on destroy , the object is set to null ( NOTE :... | < script src= '' https : //ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js '' > < /script > < button id= '' start_button '' > Start < /button > < button id= '' destroy_button '' > Destroy < /button > < script type= '' text/javascript '' charset= '' utf-8 '' > var Leaker = function ( ) { } ; Leaker.prototype = ... | Chrome Profiler Javascript memory leak |
JS | How does one add a variable string in this javascript statement ? where name may correspond to any valid string , say WebkitTransform or Moztransform , etcMy code does n't seem to work when i set the VARIABLE_NAME to WebkitTransform , but it works fine if I use WebkitTransform directly , as in without naming it via a v... | document.getElementById ( 'test ' ) .style.VARIABLE_NAME = 'rotate ( 15deg ) ' ; | variable in javascript statement |
JS | I 'm trying to create an effect that works in a queue , so that each effect starts only after the previous one finished . I was successful , but I 'm sure that there 's a cleaner way.This is what I have so far : There 's got ta be a cleaner way , right ? Much obliged in advance . | $ ( `` tr : last td : nth-child ( 1 ) div '' ) .slideUp ( 200 , function ( ) { $ ( `` tr : last td : nth-child ( 2 ) div '' ) .slideUp ( 200 , function ( ) { $ ( `` tr : last td : nth-child ( 3 ) div '' ) .slideUp ( 200 , function ( ) { $ ( `` tr : last td : nth-child ( 4 ) div '' ) .slideUp ( 200 , function ( ) { $ ( ... | Effect Queues in Javascript |
JS | I have an html select : Using jQuery , is there an event I can capture for when the select option list has been revealed ? ( the reason I need this is because I want to defer population of the list until the moment the list needs to be displayed to the user ) .mousedown works for when they click on it , but does n't do... | < select > < option > Choose one < /option > < /select > var select_reveal = function ( ev ) { ... } $ ( 'select ' ) .on ( 'mousedown ' , select_reveal ) .on ( 'keydown ' , function ( ev ) { // character code 9 is tab if ( ev.which ! == 9 ) select_reveal.bind ( this ) ( ev ) ; } ) ; | Is there a JavaScript `` select box reveal '' event or something like it ? ( using jQuery ) |
JS | I have the following code : It 's output is : The prototype of a and b has not changed and c had a new one . Am i right that this was caused by the fact that a.constructor is not equal to c.constructor and each of them had own prototype ? Are there any other circs when constructors of two objects might not be equal ? E... | var A = function ( ) { } ; var a = new A ( ) ; var b = new A ( ) ; A.prototype.member1 = 10 ; A.prototype = { } var c = new A ( ) ; console.log ( a.member1 ) ; console.log ( a.constructor === b.constructor ) ; console.log ( a.constructor === c.constructor ) ; console.log ( ' -- -- -- -- - ' ) ; console.log ( c.member1 ... | Why changing the prototype does not affect previously created objects ? |
JS | Logic : I have a dialog for converting units . It has two stages of choice for the user : units to convert from and units to convert to . I keep this stage as a state , dialogStage , for maintainability as I 'm likely going to need to reference what stage the dialog is in for more features in the future . Right now it ... | function DialogConvert ( props ) { const units = props.pageUnits ; const [ dialogUnits , setDialogUnits ] = useState ( [ ] ) ; const [ dialogStage , setDialogStage ] = useState ( 'initial ' ) ; let foundUnitsArray = [ ] ; let convertToUnitsArray = [ ] ; units.unitsFound.forEach ( element = > { foundUnitsArray.push ( < ... | Call function only after multiple states have completed updating |
JS | What is javascript : in a JavaScript event handler ? Such as : | < input onkeydown= '' javascript : return false ; '' type= '' text '' name= '' textfield '' / > | What is `` javascript : '' in a JavaScript event handler ? |
JS | My company is building a graph-view editor for chatbots . We are using Cytoscape along with the cytoscape-cola extension to accomplish this . One of the issues we are facing is dynamically adding new nodes to the graph without them overlapping with existing nodes on the graph.I have looked through previous similar ques... | const layoutConfig = { name : `` cola '' , handleDisconnected : true , animate : true , avoidOverlap : true , infinite : false , unconstrIter : 1 , userConstIter : 0 , allConstIter : 1 , ready : e = > { e.cy.fit ( ) e.cy.center ( ) } } this.graph = Cytoscape ( { ... } ) this.layout = this.grapg.makeLayout ( layoutConfi... | Dynamically adding nodes to Cytoscape |
JS | im learning javascript , and i have been following some video tutorial on youtube this is the original codeand the result of code on above is 5 main.js ( line 4 ) done main.js ( line 9 ) and i make slight change to the code into thisand the result is this done main.js ( line 9 ) 5 main.js ( line 4 ) my question are : c... | function add ( first , second , callback ) { console.log ( first+second ) ; callback ( ) ; } function logDone ( ) { console.log ( `` done '' ) ; } add ( 2,3 , logDone ) ; function add ( first , second , callback ) { console.log ( first+second ) ; callback ; } function logDone ( ) { console.log ( `` done '' ) ; } add ( ... | Need explanation about javascript function and callback |
JS | I 'm a bit confused in how functions operate in javascript . I understand that they 're all objects but how does that change how I would use them as arguments ? For instance , if I 'm trying to use a callback function where the 2nd argument is evaluated after 1000ms ... Why ca n't I achieve the same effect with : If I ... | $ ( this ) .fadeIn ( 1000 , function ( ) { alert ( 'done fading in ' ) ; } ) ; $ ( this ) .fadeIn ( 1000 , alert ( 'done fading in ' ) ) ; | When to declare a new ( anonymous ) function in javascript ? |
JS | I have an 'item ' object in JavaScript , and the item can have settings likecolor , size , etc.I need to get all possible combinations in an array.So lets say we have an item that looks like this : I need to somehow get this : | var newItem = { name : 'new item ' , Settings : [ { name : 'color ' , values : [ 'green ' , 'blue ' , 'red ' ] } , { name : 'size ' , values : [ '15 ' , '18 ' , '22 ' ] } , { name : 'gender ' , values : [ 'male ' , 'female ' ] } ] } ; [ [ { SettingName : 'color ' , value : 'green ' } , { SettingName : 'size ' , value :... | Get all possible options for a matrix in javascript |
JS | How can I fix a custom timezone on client browser with javascript ? For example , on angular I have a date `` 2015-10-16T00:00:00.000Z '' from a backoffice.I would like to have a display ( with UTC-4 New York or with UTC+2 France ) , always : 16/10/2015Read : If I use the UTC on New York , I have : 15/10/2015.Write : I... | < p ng-bind= '' ( myDate | date : 'dd/MM/yyyy ' ) '' > < /p > // Remove TimeZoneDate.prototype.toJSON = function ( ) { return moment ( this ) .format ( 'YYYY-MM-DD ' ) + 'T00:00:00.000Z ' ; } ; | Use always UTC+0 - Fix custom timezone on client browser with javascript / angularjs |
JS | I 'm using the MediaRecorder API along with the Canvas captureStream method to encode a VP8 video stream of a canvas in browser . This data is sent to FFmpeg via binary web socket.For some reason , the stream seems to be randomly switching to a lower resolution mid-stream . FFmpeg is n't happy about this : Input stream... | var outputCaptureStream = $ ( 'canvas ' ) [ 0 ] .captureStream ( 30 ) ; var mediaRecoder = new MediaRecoder ( outputCaptureStream , { mimeType : 'video/webm ' } ) ; mediaRecorder.ondataavailable = function ( e ) { ffmpegStdin.write ( e.data ) ; } mediaRecoder.start ( 1000 ) ; | MediaRecorder changes size without provocation |
JS | While writing tests with TestCafe i 'm creating utility functions , but there seems to be a problem when using the Selector ( `` ) method inside any function . The Selector ( `` ) method works fine inside test files and also when importing from another file ( utility_selectors.js ) . I think I need to include something... | import { Selector } from 'testcafe ' ; export const viewport = Selector ( '.viewport ' ) .find ( 'canvas ' ) ; import * as s from './selectors.js ' ; export const selectPoint = ( x , y ) = > { return s.viewport + `` , { offsetX : '' + x + `` , offsetY : '' + y + `` } '' } export function selectPoint ( x , y ) { return ... | How do i combine Selector with my Utility function ? |
JS | Been trying to learn BEM and while I know that BEM is not just CSS it seems like a best place to start.So I made some basic preloader css : https : //jsfiddle.net/ygz931s7/And modified it to fit BEM notation : https : //jsfiddle.net/af36921w/The problematic part was the loaded class which simplified stuff from the js s... | < div class= '' container '' > < div class= '' loader '' > < div class= '' loader__element loader__element -- left '' > < /div > < div class= '' loader__element loader__element -- right '' > < /div > < /div > < /div > .loader { position : fixed ; top : 0 ; left : 0 ; width : 100 % ; height : 100 % ; z-index : 1000 ; } ... | BEM CSS and states |
JS | I am passing a component as a prop . This is defined as below.This works fine , but I 'd like to update this definition to say , at least above props should exist , but to allow additional props.Is there a definition I can use to do this . For instance , I 'd like a component with the following signature to be accepted... | export type TableProps < T > = { contents : T [ ] , loadContents : ( ) = > Promise < T [ ] > } ; type Props = { onChangeMark : ( val : string ) = > void , ... TableProps < Attendance > } ; interface TableProps < T > { contents : T [ ] , loadContents : ( ) = > Promise < T [ ] > } ; | How to define that component passed must have certain props but allow extra props too |
JS | So I want to capture the sub-string between two special characters in JavaScript , using regular expressions.Say I have the string `` $ Hello $ , my name is $ John $ '' , I would want .match to return the array of [ Hello , John ] . *In addition , I do not want to capture the match between two matches . So I would n't ... | var test = str.match ( / ( ? < =\ $ ) ( . * ) ( ? =\ $ ) / ) ; | Matching a substring between two special characters EXCLUDING the characters |
JS | Many productions in EcmaScript are given with the following `` modifiers '' : Here are a few examples : I 've searched through the spec for the explanation , specifically Grammar Notation section , but ca n't find it . It should be there . Can someone please point me to the relevant paragraph and maybe provide a short ... | [ Yield , Await , In , Return ] ArrayLiteral [ Yield , Await ] : ... ElementList [ Yield , Await ] : ... AssignmentExpression [ +In , ? Yield , ? Await ] | What are [ Yield , Await , In , Return ] in EcmaScript grammar |
JS | I want to check whether cropping div covers images in it.Everything works fine when image is not rotated but after rotating image crop does not shows error msg ... Here is fiddle : Fiddleor another function I above code i have one image inside div.if crop div gets out of this div i m showing label bg color red meaning ... | function isCropValid ( ) { var $ selector = $ ( `` # resizeDiv '' ) ; // cropping Div var $ img = $ ( `` # rotateDiv '' ) ; // image div var $ selectorW = $ selector.width ( ) ; var $ selectorH = $ selector.height ( ) ; var $ selectorX = $ selector.offset ( ) .left ; var $ selectorY = $ selector.offset ( ) .top ; var $... | how to check whether crop div covers rotated image ? |
JS | I use the following lib to connect to the cloud controller https : //github.com/prosociallearnEU/cf-nodejs-clientI try to run it against our API and its not working and Im not getting no error message in the console , what it can be ? where does the space/org is handled here ? since when I connect from the cli it ask m... | const endpoint = `` https : //api.mycompany.com/ '' ; const username = `` myuser '' ; const password = `` mypass '' ; const CloudController = new ( require ( `` cf-client '' ) ) .CloudController ( endpoint ) ; const UsersUAA = new ( require ( `` cf-client '' ) ) .UsersUAA ; const Apps = new ( require ( `` cf-client '' ... | CF Connect to the cloud controller |
JS | Yeah , it works in my firebug console . Why does something like this present no syntax error ? Just curious about why it 's allowed . | [ ] = 5 ; [ ] = doThis ( ) ; [ ] = ( function ( ) { } ) ( ) ; | Javascript : [ ] = 5 , No Syntax Error ? Why ? |
JS | Since I started working with JS , I 've thought the only way to invoke a function on a number literal is to put it in expression position by wrapping it with parens , like so : Today , it occurred to me to try this : Why does this work ? A pointer into the official spec would be great.Edit Ambiguity was my first though... | 1.toString ( ) ; // SyntaxError : identifier starts immediately after numeric literal ( 1 ) .toString ( ) ; // `` 1 '' 0.1.toString ( ) ; // `` 0.1 '' var obj = { `` 1 '' : 1 , `` 2 '' : 2 } ; obj.1 ; // SyntaxError : Unexpected token ILLEGALobj [ ' 1 ' ] ; // 1 1 [ 'toString ' ] ( ) ; // ' 1 ' | What are the rules for invoking functions on number literals in JS ? |
JS | My main code is under chokidar watched folder , when a file changes it emit an eventThe main script is thisand this is the file test.tsI need to reimport file when I change test.ts , for example , I need thisSTART scriptOUTPUT `` aaa '' CHANGE test.ts from `` console.log ( `` aaa '' ) '' to `` console.log ( `` bbb '' )... | const fileName = `` test.ts '' ; import ( fileName ) .then ( ( t : any ) = > { t.default ( ) ; } ) ; export default ( ) = > { console.log ( `` aaa '' ) ; } ; | nodejs re-import file when it changes |
JS | WooCommerce-tables comes with classes like these , out of the box : shop_table shop_table_responsive cart woocommerce-cart-form__contents . So no table-class , which means no nifty Bootstrap-tables . Huh ! And since overriding the WooCommerce-templates should only be done when absolutely necessary , then let 's solve i... | < div id= '' app '' > ... < table class= '' shop_table shop_table_responsive cart woocommerce-cart-form__contents '' > ... ... < /table > ... < /div > let tableSelectors = [ '.some-class table ' , '.woocommerce-product-attributes ' , '.woocommerce-cart-form > table ' ] ; for ( let t = 0 ; t < tableSelectors.length ; t+... | Apply a 'table'-class to a WooCommerce table after AJAX-call |
JS | While experimenting , I came across this.When the page was reneded , I could see the following markup in the browser console : Does this mean that jQuery is running array.join ( `` '' ) in the background if the argument/parameter supplied to the .html ( ) method is an array ? I could n't find this mentioned in the docu... | < div id= '' result '' > < /div > < script type= '' text/javascript '' > $ ( ' # result ' ) .html ( [ ' < p > This is inside an array < /p > ' , ' < em > This is second item in array < /em > ' ] ) ; < /script > < div id= '' result '' > < p > This is inside an array < /p > < em > This is second item in array < /em > < /... | Does jQuery 's html ( ) method auto-join the argument if it 's an array ? |
JS | I have a Javascript application generating an XML and sending it to a REST API . The API is expecting content type : application/xml . I have tried to attach the XML to the requests in different formats : The response I get : When I try to make the same call from Postman with the raw string as the xml body , the server... | import { create } from 'xmlbuilder2 ' ; const rawXML = ' < ? xml version= '' 1.0 '' encoding= '' UTF-8 '' ? > < TokenExchangeRequest xmlns= '' http : //schemas.nav.gov.hu/OSA/2.0/api '' > < header > < requestId > 202003201315421 < /requestId > < timestamp > 2020-03-20T13:15:42.941Z < /timestamp > < requestVersion > 2.0... | Server can not consume application/xml request sent from Electron application |
JS | I have been comparing the generated javascript outputed by various calls in clojurescript and it feels like stepping on landmines . Some generate extremely readable ( even in minified advanced mode ) javascript and some decide this one method call is going to require what seems like every possible method in clojure to ... | ( ns fooModule ) ( let [ log js/console.log x ( array 5 ) ] ( log ( nth x 0 ) ) ) ( ns fooModule ) ( let [ log js/console.log x ( array 5 ) ] ( log ( aget x 0 ) ) ) ; ( function ( ) { var a=console.log , b= [ 5 ] ; a.a ? a.a ( b [ 0 ] ) : a.call ( null , b [ 0 ] ) ; } ) ( ) ; | Why does using nth in clojurescript increase my codesize by 74026 % |
JS | Possible Duplicate : What is the explanation for these bizarre JavaScript behaviours mentioned in the 'Wat ' talk for CodeMash 2012 ? When I type in the Google Chrome JavaScript console , I get as a result . However , when I typeI getas a result . I would think that both operations should return the same result , as on... | { } + [ ] 0 Function ( `` return { } + [ ] '' ) ( ) `` [ object Object ] '' | { } + [ ] in Javascript |
JS | I have gone through similar questions and answers on StackOverflow and found this : As , parseInt ( ) parses up to the first non-digit and returns whatever it had parsed and Number ( ) tries to convert the entire string into a number , why unlikely behaviour in case of parseInt ( `` ) and Number ( `` ) .I feel ideally ... | parseInt ( `` 123hui '' ) returns 123Number ( `` 123hui '' ) returns NaN | Why does Number ( `` ) returns 0 whereas parseInt ( `` ) returns NaN |
JS | The string coercion can be overwritten using the toString function.The number coercion can be overwritten using the valueOf function.The boolean coercion can be also overwritten using the valueOf function.I have n't been able to find a function that gets called for when an object needs to get converted to a truthy . Si... | var foo = { toString : function ( ) { console.log ( `` To String '' ) ; return `` bar '' ; } , valueOf : function ( ) { console.log ( `` Value Of '' ) ; return 5 ; } } ; console.log ( ` $ { foo } ` ) ; console.log ( +foo ) ; console.log ( foo == true ) ; console.log ( ! ! foo ) ; | Can you override the truthy coercion of a JavaScript Object ? |
JS | I have a ( GIS ) project which displays large amounts of customer data ( Thousands of records ) to clients . Where nescessary/possible/required , we use server side pagination/filtering/data manipulation but there are cases where it is most efficient to send the data in JSON format to the client and let their browser d... | { attrNames : [ `` foo '' , '' bar '' ] , values : [ 1,2,3,4 , ... ] ) - > [ { foo:1 , bar:2 } , { foo:3 , bar:4 } , ... ] function toObjectArray ( attrNames , values ) { var ret = [ ] ; var index = 0 ; var numAttrNames = attrNames.length ; var numValues = values.length ; while ( index < numValues ) { var obj = { } ; f... | Is there a way cleanly use hidden classes in javascript when you dont know what the properties will be ? |
JS | I found many article in stackoverflow talking about how to capture the first video image frame , but I do n't see what I 'm doing wrong on the code to make it not working . So if someone can help me , thanks a lot ! HTML code : TS Code : When I see the img in console.log I get an image , but totally white , and it shou... | < ion-button expand= '' block '' color= '' primary '' ( click ) = '' onPickVideo ( ) '' > < ion-icon name= '' videocam '' slot= '' start '' > < /ion-icon > < ion-label > Select video < /ion-label > < /ion-button > < input type= '' file '' ( change ) = '' onFileChosen ( $ event ) '' # filePicker/ > < div class= '' wrapp... | Capturing the first video frame |
JS | I 've been struggling a lot lately to find decent solution which has authentication mechanism for server and client API's.I put alot of effort trying to find working ( ! ) code samples , but could n't find any.The code from DotNetOpenAuth does n't work for me - im using vs 2010 .net 4 webformAnyway , I ca n't seems to ... | https : //accounts.google.com/o/oauth2/auth https : //accounts.google.com/o/oauth2/auth ? scope=email % 20profile & state= % 2Fprofile & redirect_uri=https % 3A % 2F % 2Foauth2-login-demo.appspot.com % 2Foauthcallback & response_type=token & client_id=812741506391.apps.googleusercontent.com | OpenID API for both asp.net and JavaScript support ? |
JS | In react , have this : As you can see , I am doing a ternary operator to output content depending on variable . I want to add style attribute in the p tag , like this : But it does n't work . I also tried : What am I doing wrong ? | return ( < tag > { variable ? < p > hello < /p > : < p > world < /p > } < /tag > ) < p style= '' color : # DF0101 ; font-weight : bold ; '' > hello < /p > < p style= { { color : '' # DF0101 '' , font-weight : '' bold '' } } > | Adding style attribute in react |
JS | Is there a way , using JavaScript , to get the color of the `` A '' element when it 's printed ? The normal getComputedStyle works only for screen media.I do n't want to read the style element . I need the computed style . | @ media screen { a { color : green } } @ media print { a { color : red } } | GetComputedStyle to other media than screen |
JS | I have a set of picture ads that I want to change the order of every day at midnight.Basically so that one day it will be like thisand the next day it will look like thisHow could I accomplish this with javascript , jquery or php . Not concerned about what language I use , just need to figure it out . Thanks.. | < img src= '' image1 '' > < img src= '' image2 '' > < img src= '' image3 '' > < img src= '' image4 '' > < img src= '' image4 '' > < img src= '' image1 '' > < img src= '' image2 '' > < img src= '' image3 '' > | Change the order of pictures at midnight |
JS | Question : when click button1 , shows : btn1 , click button2 and button3 , shows : window , why not btn2 , btn3 ? | < input type= '' button '' value= '' Button 1 '' id= '' btn1 '' / > < input type= '' button '' value= '' Button 2 '' id= '' btn2 '' / > < input type= '' button '' value= '' Button 3 '' id= '' btn3 '' onclick= '' buttonClicked ( ) ; '' / > < script type= '' text/javascript '' > function buttonClicked ( ) { var text = ( ... | trying to figure out 'this ' in some js codes |
JS | After a weird behaviour of our application ( using strophe XMPP and jquery ) , we have discovered that the jquery event loop is synchronous and does not catch exception.It means that if the first event handler raises an exception , the second one is never called.We expected to see two outputs , but the second one : `` ... | $ ( document ) .ready ( function ( ) { $ ( document ) .bind ( 'foo ' , onFoo ) ; $ ( document ) .bind ( 'bar ' , onBar ) ; $ ( document ) .trigger ( 'foo ' ) ; $ ( document ) .trigger ( 'bar ' ) ; } ) ; function onFoo ( e ) { console.log ( 'listener onFoo ' ) ; throw 'fail onFoo ' ; } function onBar ( e ) { console.log... | Why Jquery event loop is interrupted on exception |
JS | I 've this layout that was created dynamically : And I want to get the event click on each h4 class= '' name '' and show a log with the number i related.However , console.log shows only the last i related ( i=9 in this case ) , and does n't work with the other i numbers . Why does this happen ? What do I have to do ? | for ( let i = 1 ; i < 10 ; i++ ) { document.querySelector ( '.card-body ' ) .innerHTML += ` < div class= '' row '' id= '' img_div '' > < div class= '' col-12 col-sm-12 col-md-2 text-center '' > < img src= '' http : //placehold.it/120x80 '' alt= '' prewiew '' width= '' 120 '' height= '' 80 '' > < /div > < div id= '' tex... | How can I get the click event inside an innerHTML ? |
JS | I had developed a LOGO-like basic turtle graphics interpreter a few years back , I wa n't to put it on the web ( as my cousin keeps bugging me for it ) . Though I am quite new to HTML , Javascript coding I thought I would give it a try & take this as a learning experience.The below code is just for the basic UI ( my UI... | function pushCmd ( ) { var cmdText = document.forms [ `` cmd-form '' ] [ `` cmd-text '' ] .value ; var srcElement = document.getElementById ( `` source-container '' ) ; var srcText = new String ( srcElement.innerHTML ) ; srcText = srcText.toUpperCase ( ) ; if ( srcText.indexOf ( `` NO CODE '' ) ! = 0 ) { srcText = cmdT... | Self defined Javascript function not working as I expected ? |
JS | I 'm reading Eloquent JavaScript 's Map section and I 'm having trouble understanding its last paragraph : If you do have a plain object that you need to treat as a map for some reason , it is useful to know that Object.keys returns only an object ’ s own keys , not those in the prototype . As an alternative to the in ... | var anObject = { } ; console.log ( Object.keys ( anObject ) ) ; //Array [ ] console.log ( `` toString '' in Object.keys ( anObject ) ) ; //trueconsole.log ( anObject.hasOwnProperty ( `` toString '' ) ) ; //false | Does Object.keys ( anObject ) return anObject 's prototype ? |
JS | I was looking through some code from a firefox extension ( here : https : //github.com/mozilla/prospector/blob/master/oneLiner/bootstrap.js # L34 ) and I saw something I 'd never seen before in javascript . The programmer has used an associative array as the variable name . Could someone explain to me how this variable... | const { classes : Cc , interfaces : Ci , utils : Cu } = Components ; | Using an associative array as a variable name ? - javascript |
JS | I 'm trying to create a function that will arrange points in a table like as shown in the image : Code I need to modify is : Any suggestions ? How can I arrange points by row ... Please help me to do that///CODE : http : //jsfiddle.net/sYq9S/9/ | var rowsCount = 7 ; var heightTable = 700 ; var rowHeight = 100 ; //an array with divs with elements , every element has a top and left positionvar arrayOfDivs = [ ( { topPosition : 99 , leftPosition : 100 } ) , ( { topPosition : 150 , leftPosition : 400 } ) , ( { topPosition : 578 , leftPosition : 10 } ) ] ; //so here... | Arrange arrays elements with javascript and jquery |
JS | I 'm trying to access the length of the array on which I 'm using a reduce function inside that reduce , but I do n't seem to be able to do it , does anyone have any idea if it is possible to access the array object inside any of the higher order functions ? PS : I tried using this but to no success ; PSS : I want to c... | let averageRating = watchList .filter ( movie = > movie.Director === 'Christopher Nolan ' ) .map ( x = > parseFloat ( x.imdbRating ) ) .reduce ( ( total , current ) = > total + ( current / 'array length ' ) ) ; var averageRating = watchList .filter ( movie = > movie.Director === 'Christopher Nolan ' ) .map ( x = > pars... | access the array object inside a higher order function |
JS | I 'm starting to look into Javascript and JQuery ( hence my choice of example below ) . And I found that I could define a function and call it ( as expected ) , but that I could also just .. Do something else.. And that 's the question : I do n't get an error with either the function call or by just stating ' $ ' witho... | function $ ( ) { console.log ( 'hi ' ) ; } $ ( ) $ | javascript , functions vs variables |
JS | I wa n't to play around with tail call optimization in node/es2015 , but I keep getting RangeError : Maximum call stack size exceeded . So I tried a very simple test function : and it still fails . I 've tried adding 'use strict ' ; inside the function body and at the top of the file . I 've tried using -- harmony and ... | function countTo ( n , acc ) { if ( n === 0 ) { return acc ; } return countTo ( n - 1 , acc + n ) ; } console.log ( countTo ( 100000 , 0 ) ) # lang racket ( define count-to ( lambda ( n acc ) ( cond ( ( = n 0 ) acc ) ( else ( count-to ( - n 1 ) ( + acc n ) ) ) ) ) ) ( count-to 100000000 0 ) ; ~ > 5000000050000000 | Ca n't enable tail call optimization in node v6.4.0 |
JS | I want to apply a forward force in relation to the object 's local axis , but the engine I 'm using only allows to me apply a force over the global axis . I have access to the object 's global rotation as a quaternion . I 'm not familiar with using quats however ( generally untrained in advanced maths ) . Is that suffi... | this.entity.rigidbody.applyForce ( 0 , 0 , 5 ) ; w:0.5785385966300964x:0y : -0.815654993057251z:0 Math.degrees = function ( radians ) { return radians * 180 / Math.PI ; } ; //converted this from a python func on wikipedia , //not sure if it 's working properly or notfunction convertQuatToEuler ( w , x , y , z ) { ysqr ... | How can I offset a global directional force to be applied over a local axis ? |
JS | I 'm using grunt-vulcanize from an Import file with relative paths to a vulcanized.html in a new location . When the file is ready it has change the relative paths to the new location . That 's working really good for static files as images or files , but ... In the import file I have some polymer-element files : paper... | < link rel= '' import '' href= '' ../myPolymerElementsFolder/paper-fab/paper-fab.html '' > < iron-icon id= '' icon '' src= '' [ [ src ] ] '' icon= '' [ [ icon ] ] '' > < /iron-icon > < iron-icon id= '' icon '' src= '' ../myPolymerElementsFolder/paper-fab/ [ [ src ] ] '' icon= '' [ [ icon ] ] '' > < /iron-icon > < iron-... | Vulcanizing polymer one time bind src attribute |
JS | Is there any performance hit for writing a function such that local var statements are replaced with arguments ? Example : Some advantages : smaller minified size : no var statements ; less programmer time spent trying to use as few vars as possibleall local vars defined in one place ... and disadvantages : arguments c... | function howManyMatch ( arr , pattern , /*ignored : */ i , l , total ) { l = arr.length ; total = 0 ; for ( i = 0 , i < l ; i++ ) { if ( pattern.test ( arr [ i ] ) ) total++ ; return total ; } function processStuff ( /*ignored : */i , j , k ) { // use i/j/k to loop // do stuff with the arguments pseudo-array } | Is there a performance hit of replacing local variables with arguments in Javascript ? |
JS | We 've had a custom jQuery menu which has worked well on our OpenCart store . However the 2nd level child categories will not display , the PHP is n't correct on either the altered or original menu . Anything with a category with 2 or more depth will not show.So we have a 2 deep category athttp : //ocart.site/opencart/... | < ? php if ( $ categories ) { ? > < div id= '' cssmenu '' > < ul > < ? php foreach ( $ categories as $ category ) { ? > < li > < a href= '' < ? php echo $ category [ 'href ' ] ; ? > '' > < ? php echo $ category [ 'name ' ] ; ? > < /a > < ? php for ( $ i = 0 ; $ i < count ( $ category [ 'children ' ] ) ; ) { ? > < ul > ... | jQuery menu not loading PHP child categories |
JS | 10 years ago I wrote a GUI layout engine in C++ and I 'm curious how its functionality could be best approximated in the browser . 1 . C++In older GUI libraries ( like Microsoft Windows ' ) , the position and size of widgets is usually given by four numbers : left , top , width and height . My engine is different in th... | const int WINDOW_WIDTH = 400 ; const int WINDOW_HEIGHT = 300 ; CWindow mainWindow ; mainWindow.setPosition ( 0.5 , -WINDOW_WIDTH / 2 , 0.5 , -WINDOW_HEIGHT / 2 ) ; mainWindow.setSize ( 0.0 , WINDOW_WIDTH , 0.0 , WINDOW_HEIGHT ) ; const int PANEL_WIDTH = 150 ; CPanel buttonPanel ( mainWindow ) ; buttonPanel.setPosition ... | Combined percent+pixel div layout |
JS | I have a question about : Is it possible to apply it to a group of 2 or more words ? Example : I need to replace 2 words with another 2 , in the example I change 1 to another 1 . | window.location.href.replace window.location.href = window.location.href.replace ( `` -standard '' , `` -standard-upload '' ) ; | Various possibilities about window.location.href.replace |
JS | How is a JavaScript array and object transposed ? Specifically , I am trying to convert the follow x and y array/objects to the new desired x_new and y_new array/objects.GivenDesiredBelow is what I attempted.https : //jsfiddle.net/fzf03c5t/ | var x= [ 'x1 ' , 'x2 ' , 'x3 ' ] ; var y= [ { name : 'y1 ' , data : [ 'x1y1 ' , 'x2y1 ' , 'x3y1 ' ] } , { name : 'y2 ' , data : [ 'x1y2 ' , 'x2y2 ' , 'x3y2 ' ] } ] ; console.log ( x , y ) ; var new_x= [ { name : 'x1 ' , data : [ 'x1y1 ' , 'x1y2 ' ] } , { name : 'x2 ' , data : [ 'x2y1 ' , 'x2y2 ' ] } , { name : 'x3 ' , ... | Transpose JavaScript array and object |
JS | Let 's say I have a page on example.com . This page includes an iframe showing sandbox.example.com.The sandbox would be executing scripts that could be potentially dangerous . The sandbox would be a mix of my own JavaScript , running alongside untrusted JavaScript code from other sources.I would expose far fewer of my ... | -- -- -- -- -- -- -- -- -- -- -- -- -- -| example.com || -- -- -- -- -- -- -- -- -- -- -- - || | sandbox.example.com | || | ( < canvas > + js ) | || -- -- -- -- -- -- -- -- -- -- -- - | -- -- -- -- -- -- -- -- -- -- -- -- -- - | Does an iframe on a subdomain provide an adequate JS sandbox ? |
JS | I feel that im close to the answer but I am not outputting exactly the format Im looking forSo , I have this array of objects : As you can see in the data set there are repeated emails as well as duplicate objects like the last 2 in the data set.I want to turn it into this array of objects : The output has a range of d... | const data = [ { email : '100 @ email.com ' , amount : '30 ' , date : '2018-12 ' } , { email : '100 @ email.com ' , amount : '30 ' , date : '2018-11 ' } , { email : '100 @ email.com ' , amount : '30 ' , date : '2018-10 ' } , { email : '200 @ email.com ' , amount : 0 , date : '2018-12 ' } , { email : '200 @ email.com ' ... | Array of objects manipulation |
JS | I know how to do both things separately , but I 'm sure there must be a way to combine them.I have an array of categories , which I am extracting from an array of objects : But of course there are duplicates in this array . So now I doWhich works fine , I get an array of the categories without dupes . But I 'm trying t... | this.videoCategories = this.videos.map ( v = > v.category ) ; this.uniqueVideoCategories = this.videoCategories.filter ( ( item , index ) = > { return this.videoCategories.indexOf ( item ) === index ; } ) ; constructor ( private videoService : VideoService ) { this.videos = videoService.getVideos ( ) ; this.videoCatego... | Javascript map then filter unique array items |
JS | I understand that the assignment operator is right associative.So for example x = y = z = 2 is equivalent to ( x = ( y = ( z = 2 ) ) ) That being the case , I tried the following : I expected that the object foo would be created with value { a:1 } and then the property x will be created on foo which will just be a refe... | foo.x = foo = { a:1 } var foo = { } ; foo.x = foo = { a:1 } ; | Multiple assignment confusion |
JS | Please check this on Google Chrome browser : I try to replace . by , when user types somethings with . in a textbox.On Chrome browser , when user press left cursor button on keyboard ← , it can not move.Why ? | jQuery ( ' # tien_cong ' ) .keyup ( function ( e ) { jQuery ( this ) .val ( jQuery ( this ) .val ( ) .replace ( `` . `` , `` , '' ) ) ; var sum = 0 ; var tien_cong = jQuery ( ' # tien_cong ' ) .val ( ) ; tien_cong = tien_cong.replace ( / , /g , `` ) ; } ) ; < script src= '' https : //ajax.googleapis.com/ajax/libs/jquer... | Keyup event prevents arrow keys in text field in Chrome |
JS | I am trying to figure out a formula to calculate the urgency of a set of arbitrary tasks , based on the number of days until a 'deadline ' and the % completion of the task already completed.So far I have a 'function ' which gives the represents : This gives me a linear function , and the 25 in the function indicates a ... | U = ( ( dd * 25 ) - ( 100 - cp ) ) Where : dd = Day difference from deadline to current date ( in an integer value ) cp = current completion % ( in an integer value - in increments of 5 currently ) Where U < 0 task is urgentWhere U =0 task is on scheduleWhere U > 0 task is ahead of schedule ( The actual display on if a... | Calculate urgency of a task from two variables |
JS | I have a web page that is dynamically built and am trying to get links that are shared on Google+ to show snippets and look nice , an example snippet for article rendering and documentation can be found here : https : //developers.google.com/+/web/snippet/article-renderingWhen I follow the documentation my links do not... | < head > < div id= '' replaceGoogle '' > < /div > < /head > //replace google var google = ' < meta property= '' og : type '' content= '' article '' / > < meta itemprop= '' og : headline '' content= '' '+ data [ 0 ] .name+ ' '' / > < meta itemprop= '' og : description '' content= '' View beer on Beer Portfolio '' / > < ... | Google+ Snippet with Open Graph Protocol |
JS | I have static e paper but i want to develop dynamic e-paper like below urlhttps : //epaper.dawn.com/ ? page=15_04_2019_001I have no idea to start e paper dynamic below is my whole html codei am not getting any idea to implement dynamic , i have to take repeater control or grid view control to achieve dynamic e paper . ... | < ! doctype html > < html > < head > < meta charset= '' utf-8 '' > < meta http-equiv= '' X-UA-Compatible '' content= '' IE=edge , chrome=1 '' > < meta name= '' viewport '' content= '' width=device-width , initial-scale=1 , shrink-to-fit=no '' > < title > q Times < /title > < link rel= '' stylesheet '' href= '' css/main... | Trying to make epaper dynamic using C # asp.net web form |
JS | I ca n't get my api data from https : //randomuser.me/api/But when I 'm using another api like http : //dummy.restapiexample.com/api/v1/employees it works.The error : start.js | import React from `` react '' ; import `` ./App.css '' ; import Start from `` ./start '' ; function App ( ) { return ( < div className= '' App '' > < Start / > < /div > ) ; } export default App ; import React , { Component } from `` react '' ; import Axios from `` axios '' ; class Start extends Component { constructor ... | reactjs axios cant get api data |
JS | After reading through mozilla docs I found this : In the global execution context ( outside of any function ) , this refers to the global object , whether in strict mode or not.After playing with scopes for a little I found that in node.js REPL ... but when I create a script with the same line ... Is there a reason for... | > this === globaltrue $ cat > script.jsconsole.log ( this === global ) $ node script.jsfalse | 'this ' different between REPL and script |
JS | Let 's say we have such an array : myArray = [ A , A , B , B , C , C , D , E ] I would like to create an algorithm so that it will find all the combinations that add up to the whole array , where none of the elements are repeated.Example combinations : Clarification : [ A , B , C ] [ A , B , C ] [ D , E ] and [ A , B ,... | [ A , B , C , D , E ] [ A , B , C ] [ A , B , C , D ] [ A , B , C , E ] [ A , B , C ] [ A , B , C ] [ D , E ] var myArray = [ `` A '' , `` A '' , `` B '' , `` B '' , `` C '' , `` C '' , `` D '' , `` E '' ] console.log ( [ ... new Set ( myArray ) ] ) | How to find all partitions of a multiset , where each part has distinct elements ? |
JS | I had a task to do which I have accomplished almost but I have been stuck to a last part.What I am doing I have JSON data from back end which I am calling at once then showing it as a HTML table but only 10 rows at a Time , If rows are more than 10 then it will show in two parts first 10 then after 5 seconds next 10 , ... | function myFun ( ) { imageFormatter ( ) ; // here I am calling because it will call again and again $ .ajax ( { url : `` MenuCounter '' , method : `` GET '' , data : { counterCode : counterCode } , dataType : `` json '' , contentType : `` application/json ; charset=utf-8 '' , success : function ( tableValue ) { // tabl... | How to reload ajax call function in given time |
JS | So i have this array And taking the following part from the above array as example : I want to sort it like So more specific of what i want is to find in that array where string is duplicated and after check if has at the end [ .cfg.js , .ctrl.js , .module.js ] and automatic order them to [ .module.js , .cfg.js , .ctrl... | [ 'vendor/angular/angular.min.js ' , 'vendor/angular-nice-bar/dist/js/angular-nice-bar.min.js ' , 'vendor/angular-material/modules/js/core/core.min.js ' , 'vendor/angular-material/modules/js/backdrop/backdrop.min.js ' , 'vendor/angular-material/modules/js/dialog/dialog.min.js ' , 'vendor/angular-material/modules/js/but... | Javascript sort and order |
JS | Possible Duplicate : Javascript closure inside loops - simple practical example javascript variable scope/closure in loop after timeout Can you please explain step by step why the results are different ? Snippet A ( alerts 10 ) Snippet B ( alerts 3 ) | for ( var i=0 ; i < 10 ; i++ ) if ( i==3 ) setTimeout ( function ( ) { alert ( i ) ; } , 100 ) ; for ( var i=0 ; i < 10 ; i++ ) if ( i==3 ) setTimeout ( ( function ( p ) { return function ( ) { alert ( p ) ; } } ) ( i ) , 100 ) ; | Passing arguments to javascript function |
JS | I 'm using Parse.com as my backend and after Query how can I fill an array with all the data inside the Parse object ? how can I avoid re-mapping ? example : I 'm mapping my Parse object 's properties one by one : name : obj.get ( `` name '' ) , etc . is there a better way ? Should I use Underscore library , is that th... | $ scope.addContList = contacts.map ( function ( obj ) { // re-map ! ! ! ! return { name : obj.get ( `` name '' ) } ; // mapping object using obj.get ( ) } ) ; $ scope.addContList = [ ] ; var ActivityContact = Parse.Object.extend ( `` ActivityContact2 '' ) ; var query = new Parse.Query ( ActivityContact ) ; query.equalT... | How to load into an array all objects after Query Parse.com |
JS | I am trying to match hash tags and wrap them with an anchor tag . Here is the POC : I am facing a problem : if the last hash tag word is matching any other word 's first characters then its wrapping only that part of the word . For this POC , `` red '' is the last hash tag , that 's why first `` redApple '' becomes `` ... | < p class= '' display '' > < /p > var content = `` I like # redApple . I have a # black hat . # red is my favorite color '' ; var re = / ( # [ a-z0-9 ] [ a-z0-9\-_ ] * ) /ig , match , matches = [ ] ; while ( match = re.exec ( content ) ) { matches.push ( match [ 1 ] ) ; } for ( i = 0 ; i < matches.length ; i++ ) { valu... | RegEx issue with hash tag |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.