Posts by Sergio • 133,294 points
2,786 posts
-
3
votes3
answers165
viewsA: return values of a javascript object
You can use the Math.max to know the highest index. Using the spread operator you can pass all plots or filtered by rate === 0 and know the highest index. const obj =…
-
1
votes1
answer164
viewsA: Understanding the scope of Arrow Function + callback
Javascript does not stop code execution because you have a setTimeout, he keeps running the code up to that setTimeout end. If the function of that direct return without having an asynchronous part,…
-
5
votes1
answer92
viewsA: How to filter with javascript
You can do it like this: this.filtered = this.properties.filter(p => { const {lat, lon} = p.address.geoLocation.location; return Math.min(lat, lon) > 0; }); The function .filter returns a new…
-
4
votes1
answer92
viewsA: What are Renderless Components?
A component Renderless is a component that does not generate HTML itself, it exists only to structure other components and/or process data that is passed to the inside of it. A component Renderless…
-
0
votes1
answer132
viewsA: Filter table with Vue-multiselect
If your Select arrow the this.value with an array of values that corresponds to the key value teacher of the event array, so this computed can be done like this: filteredEvent() { return…
-
0
votes2
answers150
viewsA: Add Objects within a Javascript Array
You’re using data.alunos.push to insert new data into the array, when you should use .push in the specific student. For this notas has to be an array and you have to find the student you want to…
-
0
votes3
answers32
viewsA: Concatenation in function checks
In Javascript you have 3 bookmarks String, usa string template "`". onclick="return verifica(`' . $mensagemBloquear . '`);"
-
0
votes1
answer166
viewsA: Change FATHER div inside a Child frame
You can access the parent of the page within the iframe with window.parent.document. Notice also that you have frame instead of iframe. You can do it like this: (Note the jsFiddle examples) On the…
-
2
votes2
answers638
viewsA: Capture input value dynamically with Jquery
Create a function to recalculate the values and listen to changes in them that invoke the calling of this function. Something like this: $(function() { const $preco = $("#preco"); const $qtd =…
-
1
votes1
answer97
viewsA: How to count objects more cleanly?
By steps, conceptually, it could be: creates a parallel array to include counters traverses each object to test and add to the counter In practice this could be done: const array1 = [ {nome: 'joao',…
javascriptanswered Sergio 133,294 -
0
votes2
answers24
viewsA: Rendering with v-for
Two things: About reading the JSON: This code to read the file is server code, it will not work in the browser. The read-file-utf8 is a shortcut to the fs.readFile Node.js and it doesn’t work in the…
-
2
votes1
answer77
viewsA: what is capture, propagation and bubbling of events? One or more terms are the same thing? Examples!
The .preventDefault() and bubbling are different things. The .preventDefault() causes an expected/natural action of the browser to fail and the stopPropagation() stops the bubbling.…
javascriptanswered Sergio 133,294 -
1
votes1
answer38
viewsA: Changing an Existing Object
I usually have a similar function in my toolbox, but I usually use the API fn('chave1.chave2.chave3', valor). In addition to being a good idea to pass the object as an argument (and beware of the…
javascriptanswered Sergio 133,294 -
5
votes2
answers172
viewsA: Why don’t I need to declare the parameter in the function?
In JSX language it is written onChange={this.handleChange} but it’s actually the same as .addEventListener('change', this.handleChange) that is to say a callback. The moment that callback is used it…
-
2
votes1
answer85
viewsA: Error with Vuejs component, cannot declare global component in Vuejs
You have to change the order of those lines... Vue.component('insert' has to be read before new Vue({ el:'#app', because this new instance will read the <insert> inside the div #app but the…
-
1
votes2
answers206
viewsA: Iterate an object within another. Is it possible?
You need to create a function that checks whether a given object contains the key you are looking for and that if you have nested objects (or arrays) recursively traverse them by calling yourself. A…
-
9
votes2
answers312
viewsA: Decimal places in Javascript
You can use the .toFixed() to limit the decimal places: const nr = 72.10714285714286; console.log(nr.toFixed(2)); // dá 72.11 console.log(nr.toFixed(4)); // dá 72.1071 If you want to use in number…
javascriptanswered Sergio 133,294 -
1
votes2
answers48
viewsA: make images disappear depending on select
You can generate these dolls every time the value of the dummy changes... Something like that: const urlIcon = 'https://1001freedownloads.s3.amazonaws.com/vector/thumb/74889/1367934593.png'; const…
-
4
votes2
answers482
viewsA: What is the difference between `UNDEFINED` and `IS NOT DEFINED`
The difference is that undefined refers to the value of the variable and is not defined is an error message indicating that the variable does not exist in the program that is running. a; //…
javascriptanswered Sergio 133,294 -
0
votes1
answer939
viewsA: Add and save button function of an HTML Table
I think you should keep a reference of those values you add in variables... but you can of course make a table and read the value from there. An example would be: const tabela =…
-
8
votes2
answers449
viewsA: Questions about block scope in Javascript
What is the difference between block scope and function scope in Javascript? From ES6, using let or const it is possible to declare variables that only exist inside blocks {}. The most common…
-
5
votes4
answers711
viewsA: Why are literal objects declared with const in Javascript currently?
In Ecmascript 6 the var. Hence the const or the let are the modern options, and that is the only reason not to use more the var. The recommendation is not written in the ES6 specification but is the…
-
6
votes1
answer316
viewsA: replace Javascript function is not working
The result of parseFloat is a Number, and the method .replace is a String method. To do this replace you have to convert the number back to String. But maybe that’s not what you want to do... if…
javascriptanswered Sergio 133,294 -
3
votes1
answer1488
viewsA: Function Returns [Object Promise]
When you have the floor async in the declaration of a function it will return a Promise whose value you can use when Promise is solved. To use the value of const texto1 = async ()=>{ you have to…
javascriptanswered Sergio 133,294 -
5
votes1
answer68
viewsA: Taking Value from an Array of Inputs
You can pass the this as argument of this function call and thus access the value of this button. Example: function getValor(input) { var valor = input.value; alert(valor); } <script…
javascriptanswered Sergio 133,294 -
1
votes1
answer485
viewsA: My Vue.js function for currency conversion returns Nan
Your mistake was in the way you’re extracting the value of json that you receive. That key .val does not exist, you must extract directly with json[de_para]. A working example would be like this:…
-
0
votes1
answer38
viewsA: Using the result of one function in another
You have two options: a) or flames the request.get() inside CheckPassword b)or save the url/body of request.get() and consume within CheckPassword Option to) var request = require('request');…
javascriptanswered Sergio 133,294 -
2
votes3
answers214
viewsA: Change style of the last two characters of the string
You can use it like this: document.querySelectorAll('.meu-valor strong').forEach(el => { const [int, dec] = el.textContent.trim().split(','); el.outerHTML =…
-
0
votes1
answer41
viewsA: Function onClick in the inside of a form is not working properly
The problem here is similar to what was asked here, is that when the onClick is called the value of index is another that what was in the loop iteration that created this component... You can use…
-
1
votes2
answers1925
viewsA: Take Input values and insert into Onclick
Make that logic inline seems to me impractical and difficult to read... the best is to use a function that calls this function That is, for example: function onSubmit(form, btn) { btn.disabled =…
-
1
votes1
answer49
viewsA: Adding values for equal properties to an object
You can create a new object in a cycle where you iterate the elements of the initial array. With each iteration of the cycle you can check whether the object you are creating already has that key. I…
-
2
votes1
answer507
viewsA: Javascript, handling escape characters
I don’t know if this string is trustworthy... if it’s a secure string you could use the eval thus: const message = "'J\\xe1'"; const parsed = eval(message); console.log(parsed); // Já But the safest…
-
6
votes1
answer87
viewsA: How to get a list from a JSON
In this case just create an array using let currencies = Object.keys(json.rates);. The Object.keys will extract all keys from an object and create an array with them. That is to say: const url =…
-
1
votes1
answer1163
viewsA: React - Why does using a global variable to store this make React see only the last reference?
When you have a file like Input.js this file is read only 1 time. Regardless of how many components (instances) of <Input /> create, that file will only have been read once. So what happens is…
-
3
votes1
answer464
viewsA: I need help showing all the items in an array with Javascript
The problem is that every time you see that it iterates you’re rewriting the previous content and rewriting... Instead of using document.getElementById('results').innerHTML = you must use += to add,…
-
3
votes2
answers2357
viewsA: How to call two functions in onClick (Reactjs)?
You have to call one inside the other. You can find a more generic name and call both within that other more generic name function but you can only have one onClick by element. Sometimes it makes…
-
1
votes1
answer23
viewsA: Problem returning text
You’re running defineCarta(1); before carta.numImg = criarAleatorioUnico();, this makes within this function the value carta.numImg does not yet exist. Change the order of these lines and it will…
-
5
votes3
answers52
viewsA: Does code always return the last character?
The variable browserType contains a String 'mozillad'. In Javascript you can measure the length of a string (the number of characters) by accessing the property .length of the same. In this case…
javascriptanswered Sergio 133,294 -
2
votes1
answer213
viewsA: Take specific position in . each
Your problem is you’re generating duplicate Ids. HTML Ids must be unique, so when you use the selector you will only receive the first element with that ID. You have at least 3 solutions: use…
-
1
votes2
answers185
viewsA: Add onclick or listener to a non-existent element
You have to delegate that event to another element that already exists on the page. How do you say it is inserted into body that’s exactly what you should use. Then you have to check if the click…
javascriptanswered Sergio 133,294 -
1
votes2
answers2088
viewsA: Group repeated records into an array in javascript
I would approach the problem like this: a single object with a key to each city iterate the initial array to fill this object after having an object as described then generate an array again if…
-
2
votes1
answer77
viewsA: Function createelement
You have explicitly .value = num1;, so the value is always the same. To fix it you must use the . previousElementSibling that will give you the previous element. But you also need to know the…
-
2
votes1
answer110
viewsA: innerHTML does not work completely
You’re using .getElementById("msg" + 1)... ie you are always rewriting the same element. You should use the i to add this number. But taking into account that the i begins in 0 you have to add +1.…
javascriptanswered Sergio 133,294 -
1
votes1
answer84
viewsA: Return the value that is clicked from an array in a Function. I only know how to do using Event.target
This is very simple. Two steps: if you pass the this inside onclick="menuclick()" you have the element you clicked. then just extract the text with (for example) .textContent function menuclick(h2)…
-
3
votes1
answer86
viewsA: JAVASCRIPT function inside the WHILE
You’re creating elements all with the same ID. Ids have to be unique in HTML, so you have to add logic that increments these Ids (to be unique) or logic that doesn’t need Ids! I suggest the last…
-
6
votes2
answers558
viewsA: Check values within a JSON
This JSON is not an array but an Object. I agree that matriculas could/should be an array... but it is not :) If you need to check the course status you can do so: function…
-
2
votes1
answer53
viewsA: How do you take the elements
To access the attribute data- you can use the .dataset. An example would be: headerNavLink[indice].dataset.number With your code it would be: const headerNavLink =…
-
5
votes1
answer1351
viewsA: Toast materialize
Two things to fix: to API of .toast expects an object of oppositions as a first argument, passes {html: 'Item Inserido com sucesso'} instead of just the string 'Item Inserido com sucesso' the global…
-
1
votes3
answers77
viewsA: Help to reduce Javascript code
A way to eliminate code with modern Javascript (using the technique "destructuring assignment") would be like this, only in a row: var [primeiroNomeMin] = "GABRIEL gUIDETti".toLowerCase().split("…
javascriptanswered Sergio 133,294 -
2
votes2
answers1288
viewsA: Replace last occurrence of "a" in a string
If you seek to exchange all a for @ you don’t need to have a for. Just use your own regex in the string directly: var myFrase = 'aaaa'; var trocada = myFrase.replace(/a$/m, "@");…