Posts by Sergio • 133,294 points
2,786 posts
-
1
votes1
answer22
viewsA: Sum values of alt attribute by each
Hi James can use a combination of features. The steps to take are: capture the alt value convert to number add up everything An example would be like this, which does the math every time an input…
-
4
votes1
answer98
viewsA: Proxy Object in javascript
The Proxy comes to solve an old need, to be able to intercept and redirect code dependent on logic. A little abstract maybe, but (and although this is possible with elaborate methods) the Proxy…
javascriptanswered Sergio 133,294 -
1
votes3
answers37
viewsA: Add values after a separator
You have to break that value into pieces but also convert strings 2,55 in Numbers with .. Suggestion: $(function() { function converterNumero(nr) { if (typeof nr === 'number') return nr; return…
javascriptanswered Sergio 133,294 -
2
votes2
answers63
viewsA: Create a price change button
Create an object with these values and then listen to choices on select with .addEventListener('change', function() {. So you can know the price linked to each option... An example would be like…
-
5
votes2
answers118
viewsA: Why is object property automatically transformed into a string?
When you do console.log({ id : { $gte : 5 } }); You’re asking Node.js or Browser to show you something that needs to be converted into something visual. As the intended has a conversion factor each…
-
4
votes1
answer401
viewsA: how to change the display of div by js?
The method .getElementsByClassName returns a list of elements, type array, and not only an element. For this to work you must do document.getElementsByClassName('sticky')[0] or…
-
0
votes2
answers50
viewsA: Would you like to know how to receive the value of my select by clicking on an option with pure javascript?
Just listen to the event change select and determine its value. You can at any time know the value using: const select = document.querySelector('select'); console.log('O valor do select é ',…
-
0
votes2
answers127
viewsA: Convert Jquery to Javascript
Here is a hint, not tested but with reference to which line of code it matches. I’m not sure if in your HTML carousel is just one element or several... but corrects if it is not. const carousel =…
-
4
votes3
answers689
viewsA: Convert nested loops to recursive function to compute combinations
You can create arrays using math to generate combinations. An example would be like this, using the fact that the possible combinations are raised array length to the same number: const all = (arr)…
-
1
votes1
answer74
viewsA: Why doesn’t my . map run?
That method geocoder.geocode is asynchronous. That means the line geocodingResults.push(result) will be run after yours .map. It’s the same situation as this other question. For the map to have the…
-
7
votes1
answer126
viewsA: v-for vuejs how to charge with timer
To control this you need to change what Vue uses to iterate, that is to create an array and change the array at the speed you need to have the desired effect: var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9,…
-
2
votes1
answer177
viewsA: Difference between props and propsData
Both are the same thing but you make life different from the component. When defining the component it needs to have some of the structural properties of a Vue component, such as props, data,…
-
1
votes1
answer100
viewsA: Simplify foreach to update a mongoDB doc that has nested objects and arrays
I don’t know if mongoDB has functions that help in this case, but you can do a function that looks for a path in an object and returns the value you find. In the example I created below I added an…
-
0
votes2
answers52
viewsA: How to transform a simple array into . csv?
To transform an array into the format you want just one line: const conteudo = arr.map((nr, i) => `${i+1},${nr}`).join('\n'); If you are doing this on the Node.js server you have to send the file…
javascriptanswered Sergio 133,294 -
1
votes1
answer908
viewsA: Handling a txt file with javascript
If you want to extract the numbers you can do so, assuming that the file formatting is consistent: const txt = ` 916427416 Publicação de pedido de registro para oposição (exame formal concluído)…
-
6
votes2
answers96
viewsA: Use of substring for each type of situation
You can use the .split() like the fernandosavio also suggested: const [, dia, mes, hora] = 'SEXTA-FEIRA 25 JAN 20H00'.split(' '); console.log(dia); // 25 console.log(mes); // JAN console.log(hora);…
-
3
votes1
answer1299
viewsA: Axios GET Request Response is Undefined
If GetAll is a function she needs to have a return. At this point the function does not return anything... when it should return a Promise. Adds a return here: var GetAll = function () { return…
-
3
votes1
answer104
viewsA: Pass a variable as parameter, not its value
The only way to do that is with a Setter. So when the value changes to callback will be racing again. That’s what’s behind the reactivity of Vue.js for example. I leave an example. The idea is to…
javascriptanswered Sergio 133,294 -
3
votes1
answer42
viewsA: How to add and remove class according to viewport
Whenever you can cache the elements you search with document.querySelector, especially within a .resize() this may weigh the browser. My suggestion would be to do this with CSS only... using media…
javascriptanswered Sergio 133,294 -
2
votes1
answer180
viewsA: Add Vuejs models with model.number
From the start one would expect the v-model.number only return numbers, but is not the case... there is a Take on Github on this where one of the team members says that maybe in v.3 this new…
-
3
votes1
answer158
viewsA: How to receive the result of an asynchronous function and move to Return?
You need to return a trial, but in the case of request the API does not support Promises. An alternative would be to use the https://github.com/request/request-promise-native which has not been…
-
1
votes2
answers760
viewsA: What is the difference between Array/array, Object/Object, etc?
The Javascript language offers some variavies (reserved words) with pre-defined functionality. In this case of your question we are talking about primitive types, that is to say the building blocks…
-
14
votes3
answers1024
viewsA: When and how to use instanceof and typeof operator in Javascript
The instanceof and the typeof have in fact ways to use that overlap. But they also have differences that make them distinct and applicable in different cases. Notice that the typeof gives object for…
-
7
votes2
answers954
viewsA: What’s the difference between Vue and Vue-cli
Vue-cli is a tool to generate applications/projects. Run the vue-cli will ask you to choose tools to use in the project that the vue-cli will create, and depending on what you choose you get a…
-
2
votes1
answer183
viewsA: Click on Span (recycle bin icon) to trigger in my li fadeOut events and then remove
You can use const li = this.closest('li'); to know the <li> you want to remove and then li.parentElement.removeChild(li); to remove. This will change the DOM, if you have information about…
-
0
votes1
answer143
viewsA: VUE Moment.js does not update the date in real time
Within the template "global" variances within the module are not accessible, if you want to use them you have to associate to the instance, for example in data. But in your case you can do it with a…
-
1
votes1
answer51
viewsA: update the div with the checkbox value marked
Here is a suggestion: const inputs = [...document.querySelectorAll("input[type='checkbox']")]; const res = document.getElementById("resultado"); const total = res.querySelector('[name="total"]');…
-
3
votes3
answers490
viewsA: How to use foreach in Javascript associative array
In other languages like PHP for example it is normal to use myArray[] = 0; to add elements to an array. In Javascript the [] is to access properties. So if you want the same effect you can use the…
-
4
votes1
answer581
viewsA: How to turn several asynchronous requests into synchronous?
The "Vue-like" solution, that is, using the reactivity that Vue offers, is to sortOrder one computed Property that depends on this.orderInfo. This makes the code of sortOrder is run whenever…
-
2
votes2
answers126
viewsA: I can’t read this JSON
Parts, concepts to be taken into account: $.getJSON is asynchronous, you can’t just do var x = $.getJSON; the API is $.getJSON(<endereço>, callback);, that is this function consumes the…
-
3
votes1
answer50
viewsA: Create custom property in Javascript
You can use the v-bind to pass an object to the template that will record these attributes in HTML. An example would be like this: new Vue({ el: '#app', data: { customProps: { 'data-foo': 100,…
-
2
votes1
answer78
viewsA: Get all div inside a tbody without jquery
You can split the search in two steps, first with document.getElementsByName('tbodyEstados'); and then with tBody.getElementsByName('divOficina'); within a loop you execute the logic you need.…
javascriptanswered Sergio 133,294 -
0
votes1
answer53
viewsA: Return function value executed by Keyup in the VUE source field
Just pass the event and so you have available the event.target for example... That is to say: <input type="text" v-model="valor_calc_dinheiro" v-on:keyup.stop.prevent="mascara_dinheiro($event)"…
-
0
votes1
answer32
viewsA: Using component data in the create method in Vuejs
The problem is that using a "normal function" (function) changes the execution context, and the this within that function is not what you expect... You have two solutions: Usa Arrow functions And so…
-
1
votes3
answers341
viewsA: Doubt in Vue computed method using Vuex
You can think of these methods within computed as variables that update themselves, that is in the template you will have access to a "variable" named after that method. In the template you have…
-
0
votes1
answer609
viewsA: Select rows from a table with arrow keys
There are several ways to do this. I leave a suggestion that listens in the window all through events keydown and specifically by the up and down keys. You can also limit to an element and use the…
-
3
votes2
answers2045
viewsA: Vue.js: How to format a value in a v-model?
What you want to do has some complexity because you combine the v-model with the formatting of the input value the user is entering. You can do it using a value computed and using setters and…
-
9
votes5
answers4944
viewsA: Function to check palindrome
You can reverse the string and compare like this: str === str.split('').reverse().join('') const testes = ["reviver", "luz azul", "radar", "manhã"]; const checkPalindrome = str => str ===…
-
1
votes1
answer737
viewsA: javascript - Uncaught Typeerror: Cannot read Property 'Odd' of Undefined
That mistake means that bet1 has no defined value. That is, when do let bet1 = self.card.bets[i]; the object or array .bets has no value to the property i (or has value and he is undefined). Once…
javascriptanswered Sergio 133,294 -
9
votes3
answers129
viewsA: Why are Javascript objects not always JSON?
JSON is text, is a String. It is compatible with Javascript because it was created using the syntax of that language, but for a JSON to become an object it has to be interpreted ("Parsed"). Not all…
-
1
votes2
answers119
viewsA: Attributes in functions - Javascript
In Javascript the functions have similarities to objects. The word "attributes" is not correct here, but "properties", and therefore functions can have properties that in case they are functions are…
javascriptanswered Sergio 133,294 -
2
votes1
answer108
viewsA: How to move element in a straight line towards the coordinate?
Thinking about the speed formula velocidade = distância x tempo we can reach the conclusion that the increment of X should be: incrX = dy/dx. That is to say: vX = distX x tempoX and vY = distY x…
-
3
votes1
answer58
viewsA: Use return prompt with ternary operator
The prompt always returns a String, and not a number. You have to use Number() to convert to number. More than that you need to store the value in a variable in order to use as a condition and…
javascriptanswered Sergio 133,294 -
1
votes1
answer43
viewsA: Javascript - how to search for a property in an object of an (array)?
I leave an example where I invent and simplify the parts I don’t know how you want to implement: const markersData = [{ cidade: 'Aceguá', empresa: 'Empresa: JOÃO EVARISTO CASSANEGO MACHADO',…
javascriptanswered Sergio 133,294 -
1
votes1
answer31
viewsA: Problem in the ajax
The lines conectarServidor.open("GET","http://localhost/locadora/cadastro.php"); conectarServidor.send(); have to test out of .onreadystatechange = function(){ for that is the function that will run…
javascriptanswered Sergio 133,294 -
2
votes1
answer203
viewsA: Do multiple requisitions or just one?
The first option will not scale, it will not be possible to have the entire database in the client when it is too large. But the second option to make an ajax request each mouseover may be too…
-
1
votes1
answer100
viewsA: javascript, use of prompt to gather data
Since the promprt, like the alert, blocks code execution you can do it like this: const nrDeNotas = 4; // talvez no futuro isto também seja um prompt('Quantas notas?'); const notas =…
javascriptanswered Sergio 133,294 -
1
votes1
answer206
viewsA: Click on a button and get the values of a table’s row
Basically I want to obtain the values of the table cell through a button You can create a onclick button that has a JSON with the line values. An example would be: + "<button…
-
0
votes1
answer19
viewsA: Gulp JS file automation
There is a global that is available inside the file .js that is process. This global has a key process.argv that contains the arguments used to start the command. An example would be: To gulp…
-
3
votes1
answer36
viewsA: Ajax $()click event does not work
The problem is that the first line of this code will look $('#converter-tabela') which has not yet been read by the browser. The browser needs to read HTML first, or you have to have a function that…