Posts by Sergio • 133,294 points
2,786 posts
-
6
votes2
answers71
viewsA: Questions about Ecmascript
It doesn’t make much sense to start learning with outdated solutions. It would be the same as learning engineering with the knowledge that there were 50 years ago. A very clear case is that of var.…
-
1
votes1
answer112
viewsA: Vue.js edit post by id
Uses the ID value of the item to be edited in editingTour, and only false for when there is none (or -1 to indicate that it is worthless). On the button to edit assignments the ID: <button…
-
7
votes1
answer71
viewsA: Recursive Problems - Too Much Memory - Angular 9 - Settimeout()
That one subscribe must have a unsubscribe. This is common practice in other libraries but also in Angular. That is, to invoke the subscribe returns a callback to be able to do unsubscribe, and so…
-
1
votes2
answers122
viewsA: array.push() inside mysql.query callback (nodejs)
The problem is that db.query is asynchronous and the callback is called after the rest of the code (the if/else) happen. That is, the array errors not yet have mysql data. Two solutions: a) Usa…
-
2
votes1
answer164
viewsA: How to hide/show my HTML elements?
In HTML you can only have 1 unique ID per page, ie several elements with the same ID is invalid HTML. To select multiple elements you can use classes. It is also possible to have a selector that…
-
2
votes1
answer82
viewsA: .then() in Async/Await
You are almost there! What is missing is having a function that calls itself, and then passing a counter to increase the values... You can do it like this: const delay = (str) => new…
-
1
votes1
answer46
viewsA: Subroutes in Node JS
Express checks the routes in the order they were registered, and the first that checks the condition receives the link. That is, it will check tasks/:id first and being that /:id is generalist he…
-
1
votes3
answers140
viewsA: How do I place a conditional within a . foreach() in Javascript?
The best way to do this is by using a .reduce. That way you can check every iteration if the medicine exists and join it to the array or not. A suggestion would be: const result = await…
-
1
votes1
answer31
viewsA: Error when bringing values inside an object with an array inside
Several errors in your code... 1- const areaDiv = document.querySelector('secaoProdutos') lacks the . to indicate the class selector 2- Use const, or let within a try{} will close this variable…
javascriptanswered Sergio 133,294 -
0
votes1
answer17
viewsA: How to capture another element within a loop to hide it
Some mistakes to take into account: item.querySelector('ul') will give empty because these elements are siblings (brothers, on the same level) item.classList.add('show') will add the class to the…
javascriptanswered Sergio 133,294 -
3
votes1
answer66
viewsA: compare javascript objects
The problem with this function is that it compares only the first depth level of the object. That is, when comparing numerical values all right, but when comparing the value of a property that is an…
-
4
votes4
answers292
viewsA: How to find the index of an object in a javascript list
Objects with the same content are not equal, that is to say comparing objects with equality is always different unless they are a reference to each other. This happens because each object is a…
javascriptanswered Sergio 133,294 -
1
votes1
answer57
viewsA: I would like to apply an animation in <Nav>. I would like to make it appear by clicking . menu_burger, from left to right
Two options: Keeping the JS you need to add the CSS that changes the left of ul for 0. The only solution I see with CSS is using the selector + but then you have to change the order in the DOM and…
-
1
votes1
answer295
viewsA: Get hour minutes and seconds in javascript
In Javascript you can save a date to an object (instance) Date. This instance has methods from which you can extract its components such as date, year, hours, etc... You can read more about it here…
javascriptanswered Sergio 133,294 -
3
votes2
answers34
viewsA: Reveal the Boolean value
To know the biggest number you can use the Math.max (also described in this other question), But in general I do not advise to have a function that returns either Boolean or number... it is better…
javascriptanswered Sergio 133,294 -
5
votes4
answers823
viewsA: Transform String Array into Object Array
Assuming you always have a space between the values you want to read you can make a mapping with a reduce inside to extract these values. A suggestion would be so: const data = ["TagFuncao:CN…
-
3
votes1
answer131
viewsA: How to Stop an Infinite Loop For - Vue
Since all that this component needs comes from data that this.getCasos() was then seek them (or the values they generate) must by definition be computed properties, thus creating a reactive flow. As…
-
1
votes1
answer27
viewsA: Single Import - AJAX / Javascript
What is done for such cases is to remove the headphone from the event and disable the button after pressing once... this could be so: const botaoAdicionar = document.querySelector("#btn-buscar");…
-
2
votes1
answer45
viewsA: Replace working only on the log console
The same way you use document.getElementById('textMonika').innerHTML to read the content you must also reset the content. That is, the value you have in momo has to be rewritten with…
javascriptanswered Sergio 133,294 -
0
votes1
answer69
viewsA: How to publish a package to NPM with custom CLI
In these cases what is done is to publish a package with the product name, but with an external layer that is the installer itself. That is, when downloading the package it can not use, only after…
-
1
votes1
answer59
viewsA: Selects with client-side nodejs+mysql
There is a big difference between PHP and Node. PHP gives the illusion that you can run Mysql commands on the client side because PHP can have a mix of HTML, Mysql and PHP in the same file that…
-
1
votes1
answer82
viewsA: How to calculate hours via reduce?
You can make it simpler in one .reduce, with some support functions. I strongly advise against adding methods to the Date prototype such as Date.calcHrTrab. A suggestion would be so: const registos…
-
2
votes1
answer106
viewsA: properties, and 'i18n' does not exist in type
Take a look at the examples of vue-i18n here. What you’re missing is creating an instance of VueI18n and not only export a configuration object. Your index.js should export this Singleton like this:…
-
2
votes1
answer26
viewsA: Navigating between the contents of an array
Did you answer your question... task[1] is a correct way to access the second element of the array. Notes that querySelectorAll returns a collection, more or less an array. Then, to answer your…
-
1
votes1
answer44
viewsA: Removing a class from a div by clicking on the select option
Some things wrong: let divs = document.querySelector('[divs]') returns the first element, you must use querySelectorAll and iterate with a foreach The onclick in the element option does not do what…
-
2
votes1
answer1413
viewsA: use vueJS’s Watch() method to track changes in the values of a variable
Several problems in your code... here are fixes: on Watcher you’re using if (status == 'a') { but this status is not part of the function’s arguments... or you use status(status) { in the function…
-
2
votes2
answers90
viewsA: Using . map() Create a variable that contains all user ages: [23, 15, 30]
You can’t just change the value of item, the method of arrays .map( need a return to have the substitute value for each position of the iterating array. in view of item = you need to use return.…
-
2
votes2
answers142
viewsA: How to sort an object with Javascript?
The position of keys in Objects is not guaranteed in Javascript, that is the role of arrays. In practice, in your code you are already working with an array when you use Object.values() so it would…
-
1
votes1
answer351
viewsA: Fill in input according to select
Two problems: The line var idsubcategoria = $("select#idsubcategoria").val(); is run before select changes. You are always sending the same value, the initial, to the server... Put that line inside…
-
2
votes1
answer39
viewsA: Problem in Adding Multiple Inputs
Some problems to take into account: []is an array, to join items/values, you must use a number to add. parseInt should be used with Radix, i.e. 10 as second argument. I prefer to use Number(). An…
-
0
votes1
answer28
viewsA: How to fix this problem by keeping the "player" inside the "zone"?
You need to know the size of player and do the math, that is to take into account the width and height so that you can know the limits that the axles can have. Notice it might be a good idea to use…
javascriptanswered Sergio 133,294 -
1
votes2
answers55
viewsA: GET request equivalent in separate files (controller and route)
Your problem is in the syntax of exports.getHome = (isAuth),(req, res) => {. That one isAuth (which is a middleware) cannot be exported that way. You could export an array with these two…
-
1
votes2
answers1319
viewsA: How to change the value of a variable within a javascript function
Notice that your function has asynchronous parts and so you can’t have one return of a synchronous value. The return you expect from this function has to be consumed with a .then( asynchronously.…
javascriptanswered Sergio 133,294 -
3
votes1
answer73
viewsA: Create object containing only some attributes of another
You can add to the prototype something similar (not very advised) or create a function for it. Using a function for this could be like this: function getSubSet(object, types) { return…
-
1
votes2
answers812
viewsA: Abbreviate names with javascript
This is more complex than it looks and Javascript is not very good at this because it is difficult to detect capital letters. Letters like Ì, Ó, Å are capital letters but a regex with A-Z don’t…
-
3
votes1
answer236
viewsA: Run mouseover function on Avascript only once
You can use the .one( jQuery. It will fire at most once per element and per event. In your case it would be: $(".linha").one('mouseover', function () {…
-
5
votes1
answer37
viewsA: What is the difference between canplay and canplaythrough?
The difference is subtle, canplay indicates that an object is available to start the presentation/display. The event canplaythrough is triggered when enough content of that object is already in…
javascriptanswered Sergio 133,294 -
5
votes2
answers152
viewsA: Can anyone explain to me how this code works?
You put two questions: how the code works if there is no simpler way The second question generates answers based on opinions, depends on the case, the application and the data available... so I will…
-
3
votes2
answers44
viewsA: Is Lodash still needed with ES6+?
Lodash, like jQuery, Mootools or Rxjs are toolboxes. While using ES6 much of the functionality that Lodash offers needs many lines of code to implement and Lodash ensures tested tools in production…
javascriptanswered Sergio 133,294 -
7
votes2
answers608
viewsA: Take the smallest value of an object array
You can spread an array to Math.min to give you the lowest value. For example: const valores = object.programmers.map(({currentTasks}) => currentTasks) const menorValor = Math.min(...valores);…
-
3
votes1
answer39
viewsA: Add comma values if the key is equal
There are several ways to do this... if the name is the only key you can make an object and concatenate the value in value of key name. Something like that: const array = [{ name: "city", value:…
-
4
votes1
answer94
viewsA: Function Listener being fired without Event having occurred, Javascript
When you’re creating that addEventListener you are calling the function, not passing as callback. To pass as callback you should only use item.addEventListener("click", changeBar). But how obvious…
-
3
votes1
answer55
viewsA: Why can’t I access the variable within a function?
In "old" Javascript it is possible to declare functions within a block, i.e.: {} and access that declared variable with var off the block. This is not possible in functions (neither in old…
javascriptanswered Sergio 133,294 -
2
votes1
answer116
viewsA: Uploading files with Vue.js and Filepond
The formData.append takes 3 arguments. The name to pass to form, the value (in this case the file) and finally the file name when it is a Blob. Now you can know the file name via .name your code…
-
1
votes2
answers67
viewsA: How do I value my input to appear in a div or <p> as number. But nothing appears. When it appears it is Nan
some concepts that are failing you: let inputsaldo: the way you are using that value is read immediately when the page loads. I think what you want is to read the value when the button is clicked.…
javascriptanswered Sergio 133,294 -
1
votes1
answer27
viewsA: Run code after first lines
That method .load() accepts a function as the second or third argument that will use as callback when the .load ran. So instead of using that IIFE you can put that code inside that callback:…
javascriptanswered Sergio 133,294 -
4
votes3
answers67
viewsA: Knowing which element triggered the event
It is possible to know which classes of the element triggered the event yes. You can use this inside that function, which will be the element clicked, and then know the classes of that element or…
-
2
votes1
answer303
viewsA: How to use more than 1 dynamic class with vuejs?
Creates a computed Property make this logic. In the Vue API you can return an array with strings and objects (similar to what you are doing in the template), and it would look like this: In the…
-
4
votes1
answer59
viewsA: Doubt about Map/javascript
Your starting point is an Array: [{name: 'Rui', sex: "m"}, {name: 'Ana', sex: "f"}];. The .map() traverse each element (2 in this example) and lay out the iterated object. Then you only need logic…
javascriptanswered Sergio 133,294 -
0
votes1
answer44
viewsA: Problem with Javascript String
The parseInt(numero, 10); converts a number into a string, and so separate does nothing as its return is not used. You can do it like this: const numero = window.prompt("Informe um número para ver o…
javascriptanswered Sergio 133,294