Posts by Luiz Felipe • 32,886 points
746 posts
-
5
votes2
answers124
viewsA: How to know how many times an object appeared in the array
We can create a function that takes two arguments: The array object; The property we’ll use to count. Something like that: function countObjects(input, prop) { // Criamos um objeto que vai armazenar…
-
1
votes2
answers52
viewsA: Doubt in the structure of the code
The React.Component is a class? Yes, it is a class. As specified in API of React, to create a class component, you must extend the class Component, exposed by React. The render() is a method? Yes,…
-
0
votes2
answers2574
viewsA: error in post request using server-side buttons
The mistake UnhandledPromiseRejectionWarning is invoked by Node.js whenever a Promise is rejected and does not receive due treatment. [...] I know this mistake is due to the fact that service being…
-
6
votes1
answer328
viewsA: How to get all keynames within localStorage
You can use the Object.keys for this. It returns a array with all the keys of the object. You can wear something like that: const keys = Object.keys(localStorage); console.log(keys); To create the…
javascriptanswered Luiz Felipe 32,886 -
10
votes2
answers1395
viewsQ: How do I allow only certain applications to access my API?
I am developing an API using Express, which should be used only by an application in the browser, built using React and an application, made using React Native. The question is: how can I restrict…
-
4
votes1
answer168
viewsA: Return in Promise
How are you making use of Promises, you need to chain a then to access the value solved by the catch to carry out the process of errors. You can do something more or less like this: // Note que…
-
5
votes2
answers796
viewsA: How to separate a string by commas, except when you have a space later
You can use the following regular expression to make the division: /,(?! )/ Being: , selects all the commas; (?! ) one Lookahead negative which ensures that there can be no spaces after the comma.…
-
4
votes1
answer108
viewsA: Is there any way to hide Ajax in a web application?
There is no way to "hide" AJAX, after all, there is nothing different between it and a common request that your browser does, except the fact that it is asynchronous. Any request you make is subject…
-
1
votes1
answer128
viewsA: Take a value of a cell[0] of a . date()
As shown by documentation of the method data, you can pass a key as first argument and the corresponding value will be returned. You can also use the notation to access properties of a object…
-
5
votes3
answers965
viewsA: List JSON data with Javascript
Your problem is that you are redefining the HTML of the item after each iteration (loop). This will only make the last ID of the array be shown, since all previous ones have been reset by the…
-
2
votes1
answer308
viewsA: Any programs that convert html, css and js into executable?
You can use the Electron, a framework of open source developed by Github. With Electron, you use Javascript, HTML, and CSS to create cross-platform desktop applications (Macos, Linux, and Windows).…
-
2
votes2
answers45
viewsA: Sum selected items
You have two mistakes in function calculaTotal: 01. Taking into account that you use a comma to separate decimals, Javascript does not understand that it is a decimal number. Thus, you must make a…
-
0
votes1
answer373
viewsA: How to dynamically assign the selected value of a select with ejs?
You have some ways to solve this. 1. Make a check on each <option> Using the ternary conditional operator, you can assign the attribute selected to the <option> desired. Something like…
-
15
votes5
answers24456
viewsA: AJAX request with pure Javascript (no Apis)
With the new browser Apis instead of using XMLHttpRequest, we can use the API fetch to perform asynchronous HTTP requests. The use of fetch is much simpler compared to its predecessor. In addition,…
-
1
votes2
answers215
viewsA: Splitting a string into an array of strings from the occurrence of a date
You can use a regular expression to achieve the expected result. Although it does not guarantee success if the passed string is not standardized. Analyzing the pattern of the string provided in the…
-
2
votes2
answers2285
viewsA: How to change the style of an "input" field of type "range" using only CSS (and maybe some webkits)?
You must use the pseudo selector ::-webkit-slider-runnable-track to style the field rail and the pseudo selector ::-webkit-slider-thumb to style the "selector" of the field: input[type='range'] {…
-
2
votes3
answers100
viewsA: Problems with array manipulation to find result
I was able to solve the problem using the following approach: function lastRockWeight(originalRockList) { // Função para sortear os elementos. function sortFunction(a, b) { return b - a } // Sortear…
-
7
votes2
answers3800
viewsA: Format number with Javascript
Instead of using regular expressions, you can use Javascript’s native API to achieve the same result more simply. To fix the number of decimals, you can use the method toFixed: (999.9).toFixed(2) //…
-
1
votes1
answer73
viewsA: Bug in app algorithmia
According to the documentation made available by Algorithmia, the method pipe returns a Promise. That way, you need to chain it into a chain of Promises: const algorithmia = require('algorithmia')…
node.jsanswered Luiz Felipe 32,886 -
0
votes3
answers240
viewsA: Randomly choose files in Nodejs
You can also create a function that does this all asynchronously, using callbacks: const fs = require('fs') const path = require('path') function getRandomImageData(dir, callback) { fs.readdir(dir,…
-
2
votes1
answer192
viewsA: pass a select value to a php page without refreshing the page!
You need to make an asynchronous request (more commonly known as AJAX) to achieve what you want. Assuming you have a PHP page that handles the data you send, you can use jQuery and do something like…
-
2
votes1
answer213
viewsA: Columnchart not reverting colors of options google Charts
Giving a search in the documentation, I found something that can help you. You can also pass column color within the method arrayToDataTable. See the example below, reading the comments: var data =…
-
3
votes6
answers4637
viewsA: Dual in function and for
Assuming: The tree begins with 1 metro; Growth begins in the summertime; There are four stations, arranged in the following order: Verão -> Outono -> Inverno -> Primavera And that growth…
javascriptanswered Luiz Felipe 32,886 -
-1
votes1
answer108
viewsA: How to add data-slider-bg and . data(slider-bg) not to give error in Validator W3?
Your problem is that slider-bg is not a valid attribute. You can reverse this situation by changing all references to "slider-bg" by a data attribute, as an example, "data-slider-bg". Obviously we…
-
1
votes2
answers375
viewsA: Multiply input values
The problem is that you were using the addition operator (+=). To multiply, you must use the multiplication operator (*=). You can even simplify your code if you want: const fields =…
javascriptanswered Luiz Felipe 32,886 -
5
votes2
answers274
viewsA: How to use querySelectorAll without having to specify array elements afterwards?
Unlike jQuery (which some would say is a bit simpler), when you use the method querySelectorAll, an object NodeList is returned, which is similar to a array and containing all the elements selected.…
javascriptanswered Luiz Felipe 32,886 -
2
votes1
answer108
viewsA: Check if input value contains specific word, using jQuery
You can use a condition for this by using the method indexOf. Something like that: $('#youtube').on('change', function() { var value = $(this).val() if (value.indexOf('.youtube.com/watch?v=') ===…
jqueryanswered Luiz Felipe 32,886 -
0
votes1
answer48
viewsA: Server IP Problem
Since Cloudflare is acting as proxy, the IP of the user accessing the page is overridden by the Cloudflare IP. Of Stack Overflow in English (free translation with some modifications): Extra server…
-
4
votes1
answer65
viewsA: How do I make a script work in a specific browser?
You can use the property navigator, accessible through the global object window. This property contains various information related to the user’s browser. For this answer, we will focus on the…
-
3
votes3
answers316
viewsA: Make image appear/disappear by clicking
You can use the method html to add the image and text in HTML format. Something like that: $('#service').on('change', function() { var value = $(this) .children('option:selected') .val() if (value…
-
1
votes1
answer46
viewsA: Correct alignment
You can use the flexbox to do what you want. Basically, we create a layout two-line (rows) and inside them we put our blocks. For the blocks to break as the screen size of the user decreases, just…
-
2
votes4
answers235
viewsA: Setinterval calling function only once?
Setinterval calling function only once? The function, in fact is being called correctly every 3 seconds. The problem is that your setInterval simply add the class ativado every time it runs every…
javascriptanswered Luiz Felipe 32,886 -
6
votes1
answer2524
viewsA: How to remove an object from an object array within another object array, in javascript?
First, you need to establish a scheme of what you want to do: You have a array (in response, I will call this array of main array). That one array has several objects inside. These objects have a…
-
1
votes2
answers865
viewsA: Stop running a javascript function, inside jQuery each?
As suggested in the comments by Maniero, the most ideal is you use the loop for. Something more or less like this: function getEl() { var $els = $('ul > li'); for (var i = 0; i < $els.length;…
-
6
votes5
answers9010
viewsA: How do I multiply an array within a function in JS?
You can use the rest operator for that reason: function mult(...terms) { let current = 1 for (const term of terms) current *= term return current } console.log(mult(1, 4, 7)) If you want to use one…
-
6
votes1
answer395
viewsA: I cannot access the data using the fetch API
Your problem is that Body.json returns a Promise, but you are not waiting for your resolution to use it. This causes you to print on the console to Promise in itself, and not its solved value. Just…
-
13
votes3
answers689
viewsQ: Convert nested loops to recursive function to compute combinations
I did a job for compute all combinations of an array. The problem with my approach is that it only "generates" three-digit combinations (array length past 3), since I have 3 nested loops. If I…
-
7
votes3
answers1959
viewsQ: Where should I really keep my JWT token?
In many tutorials (mostly Single Page Applications), the most common authentication method is JWT token. The problem is that most of them recommend persisting this token in the localStorage browser.…
-
3
votes1
answer351
viewsA: Is there any way to block the rendering of a particular component in React?
If you want to filter some element from prop children React, you’ll need to use the API React.Children: https://reactjs.org/docs/react-api.html#reactchildren You can then use the method…
-
0
votes1
answer721
viewsA: How to Add Age to Input
The term anos is not being entered because you are only entering the numeric value calculated in input: document.form.idade.value = (calculateAge(junta)) To include the term anos, you must invite…
-
7
votes2
answers1087
viewsA: How do I identify if a link was opened by an iframe in a new tab?
That can’t be done in most cases. This impossibility is a security measure adopted primarily to prevent threats such as XSS. However, if the iframe has the same origin of your site, you can access…
javascriptanswered Luiz Felipe 32,886 -
5
votes4
answers720
viewsA: Change comma per point
Your code does not work since you are using the replace to exchange points (.) for "nothing" (''). Besides, I think the loop while not so necessary in this situation. You can then do something more…
javascriptanswered Luiz Felipe 32,886 -
4
votes1
answer2934
viewsQ: How to pass parameters on events in React?
Assuming the code below (line 15): import React from 'react' import ReactDOM from 'react-dom' const items = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] function App() { function handleClick(item) { alert(`Você…
-
2
votes2
answers169
viewsA: Recover value from input data
According to the documentation, the <input> of the kind date will always return a string in format AAAA-MM-DD, that is, year, month and day. You need to create a function to turn the date into…
-
1
votes1
answer53
viewsA: Sort array by first coming the object
It is not possible to do what you ask. On an object, all properties that has key numerical are placed up and drawn automatically, even if you create the object originally with them "below": const…
-
2
votes1
answer4069
viewsA: What are jQuery’s AJAX beforeSend arguments for?
In accordance with indicates the documentation, the option beforeSend should be used to perform effects (or change operation options) before the request is made. The arguments: jqXHR: one superset…
-
3
votes1
answer103
viewsA: Create menu inside an Alert() with repeat loop
It is possible to create this large menu within a dialog box using only a repeat loop? Quick response: nay. The alert does not work as a checkbox. If you create a loop that calls for alerts (alert)…
-
3
votes2
answers9712
viewsA: What does the npm build command do?
The archive package.json: All Node projects that use some package manager, such as NPM or the Yarn have a file package.json, that defines the project metrics in general, identifying dependencies,…
-
1
votes1
answer33
viewsA: Error 500 when performing an authentication request with Adonisjs
Like the status code is 500, probably an error in the code, see: You wrote the method attempt incorrectly. In your code, there is this excerpt: const token = await auth.attemp(data.email,…
-
10
votes2
answers12531
viewsA: Check for special characters in a string using Regexp
The pattern \W will select all characters that are not alphanumeric, that is, select all characters except letters (A-Z), numbers (0-9) and underline (_). So we can build a pattern. So: const pass1…