Posts by Luiz Felipe • 32,886 points
746 posts
-
2
votes2
answers44
viewsA: Removing the CSS class according to screen resolution
You must use the event resize for this. See the documentation of Handler jQuery. Thus: $(function() { $(window).resize(function() { if ($(this).width() < 1200) {…
-
0
votes1
answer658
viewsA: How do I show the error message sent by Express?
When Axios makes a request that finds a status error - 4xx or 5xx -, an error will be thrown. This error will be captured by the method catch, of his Promise. This error will contain an object…
-
3
votes1
answer94
viewsQ: What is the "y" flag in regular expressions? What is its function?
Some time ago I discovered that regular expressions can also use the flag y, call for Sticky. I did not understand very well its function. What is its purpose? Is there any relation with another…
-
2
votes2
answers57
viewsA: Format string for (dd/mm)
It is also possible to use regular expressions to do this. See: /^(\d{2})(\d{2})$/ In the above expression, we create two capture groups. Each one of them will search by double-digit sequence. For…
-
3
votes2
answers767
viewsA: Dynamically add images with Javascript
Beyond the createElement, demonstrated in another answer, there’s the builder Image, unique to create elements img — HTMLImageElement. const button = document.querySelector('button');…
-
4
votes1
answer409
viewsA: How does attribution work via disruption?
Breakdown assignment is a feature introduced in Ecmascript 2015 (ES6). It is basically a syntactic sugar to obtain object values or arrays. In your example, you are disrupting the properties title,…
-
1
votes2
answers239
viewsA: Promise on JS How to Abort/Cancel an Ongoing
As already mentioned in other answers, there is really no possibility to cancel promises in Javascript. After all, as its name says, it is a promise, therefore, at all times there must be a…
-
2
votes2
answers135
viewsA: How to vertically align awesome font icons?
Just use Flexbox, applying the following styles within the media query: nav { display: flex; justify-content: space-between; align-items: center; } To magic is made by display: flex and by…
-
0
votes1
answer197
viewsA: Api headers error with nodejs
The problem is that you are always running the following code: res.status(404).json({ message: 'Usuario nao encontrado' }); It defines the status of the answer as 404 and a response in JSON, which…
-
1
votes1
answer505
viewsA: Change component properties on different pages
You can use props in its stylized component. For this, just use the interpolation syntax, passing a function, which you will receive as parameter props footsteps. An example: const Text =…
-
3
votes2
answers201
viewsA: How to remove repeated elements from an object array by preserving the object that has a different id property than null
If you want a slightly more performative solution, you can use a loop for conventional: const userPermissions = [ { id: null, description: 'Tela teste 4', screen_id: 6 }, { id: null, description:…
javascriptanswered Luiz Felipe 32,886 -
2
votes2
answers277
viewsA: Bashscript. How to execute a command at a given time?
You must use cron. For this, you must edit your file crontab. Utilize: sudo crontab -e And insert the following content: 07 15 * * * /Path/to/your/script.sh It will run the script every day at 3:07…
-
8
votes2
answers686
viewsA: How to join two object arrays by different keys?
You don’t even necessarily use Lodash: const mergedScreensAllCompanies = [ { id: 1, description: 'Cadastro de usuários' }, { id: 2, description: 'Cadastro de filiais' } ]; const userScreens = [ {…
-
2
votes1
answer120
viewsA: jQuery for Pure Javascript (use export Function ES6)
First of all, it is worth making clear that in Javascript, an anonymous function is not necessarily a Arrow Function. Anonymous functions are simply those not named. See, first, an example of a…
javascriptanswered Luiz Felipe 32,886 -
5
votes1
answer29
viewsA: The number and the letter stick together when I try to compile a variable
Concatenation does not automatically add space between your operands. This means that you must manually place space in the string: int numero = 24; System.out.println("Eu gosto muito de " + numero);…
javaanswered Luiz Felipe 32,886 -
2
votes1
answer27
viewsA: Error with Object Properties
Form elements will have field properties according to their Ids. So, if a form has a input with the ID name, the form will have a property name, which will match the input#name. Thus, the error is…
-
3
votes1
answer396
viewsA: React does not render the result of this code
This is happening because each component of React can only render a son at a time. If you notice your code, the component App is trying to return two elements at once: h1 and ul - which are…
-
2
votes1
answer70
viewsA: Count of new lines in Node
You can use the String.prototype.match, that tests a string using a given regular expression. In this case, we will use the following expression: /\n/g That will fetch all line breaks contained in…
-
7
votes1
answer148
viewsA: Why does this "for" with double condition give infinite loop?
The infinite loop happens because, in this case, the [condição] of the loop for will always be true. Like c (0) at all times will be minor that d (3), the operator’s second operation OR || will…
-
4
votes2
answers96
viewsA: Remove elements created within a function
You are removing all elements because of this excerpt from your code: document.querySelectorAll('.teste1').forEach(e => e.remove()); He will basically select all added elements and iterate over…
javascriptanswered Luiz Felipe 32,886 -
5
votes2
answers347
viewsA: Doubt about the use of the Join method
There is a difference between the two examples. Also, this behavior is not due to the console.log nor the method join. This is by the method toString array, which is called when concatenation is…
-
2
votes1
answer139
viewsA: What is the difference between the pseudo class :root and the * {} in CSS?
No, they don’t have the same function. Of wiki W3C: The pseudo-class :root represents an element that is at the root of Document. In HTML, it will always be the HTML element. Similarly, if you are…
-
5
votes3
answers101
viewsA: Why am I not able to modify the class of the element with the classList property?
This happens because the value returned by Element.classList is a DOMTokenList, that despite having similar behaviors to array, does not always share the same behaviors. An example of this is to…
javascriptanswered Luiz Felipe 32,886 -
5
votes1
answer44
viewsA: Problem with Javascript Class Method
If you are using classes, you have no reason to do this kind of thing. Create methods and properties using this, that will be encapsulated in class instances. Something like this: class User {…
javascriptanswered Luiz Felipe 32,886 -
12
votes3
answers598
viewsA: What is the difference between keys and parentheses in an Arrow Function in Javascript?
First of all, it is worth noting that this is not something exclusive to React. It is a syntactic feature of Javascript. It was introduced in Ecmascript 2015 (ES6), with the addition of Arrow…
-
2
votes4
answers21920
viewsA: How to transform string into character array?
In newer versions of Ecmascript, you can also use scattering operator, which will convert the string, which is an iterable, into an array. Thus: const string = 'oi'; const array = [...string];…
-
1
votes1
answer32
viewsA: Variable running on its own
The problem is that the $(), a command override, will capture the value of the command you pass in and, in your case, insert into the variable criar. This makes the command mkdir is executed during…
-
3
votes1
answer69
viewsA: How do I bring an HTML code stored in the Mysql database and print it on screen using MVC Express Node.js Project?
According to the documentation of the EJS, the tag you are using (<%=) will print text escaped. To print text that is not escaped, you must use the tag <%-. Thus: <%- topico.mensagem %>…
-
4
votes1
answer231
viewsA: How to use IBM Cloud services with POST request in Python?
According to the documentation, you must use the endpoint /v1/recognize from the base URL you receive. This base URL you receive is the:…
-
8
votes1
answer385
viewsQ: Would "Promise.all" (and other similar functions) be an example of Javascript parallelism?
In Javascript, we have the Promise.all, that solves an array of promises in a single Promise. This process is apparently parallel, since the promises are resolved at the same time, and not in a…
-
9
votes1
answer331
viewsA: What does the "$" dollar mean in the browser console or in Javascript?
Shortcuts present in developer tools. The dollar sign $ works as a shortcut to document.querySelector. Already the $$ functions as a alias for document.querySelectorAll. The only difference is that…
-
11
votes3
answers5507
viewsA: Count how many elements are duplicated in a string
You can create an object that stores all the letters of the string, followed by the number of occurrences of the character. Then, just return the number of properties of that object whose value,…
-
8
votes3
answers717
viewsA: Ternary operator with three possible conditions
You can use ternary operators nestled. Something like that: function getClass(status) { return status === 0 ? 'default' : status === 1 ? 'icon-1' : 'icon-2'; } console.log(getClass(0));…
javascriptanswered Luiz Felipe 32,886 -
2
votes1
answer104
viewsA: Nodejs - Make an algorithm that reads the height and enrollment of ten students. Show the enrollment of the highest student and the lowest student
First, how do you want to store multiple information from the same entity (in case a student), it is worth it to you to create a single array of objects instead of three arrays, one for each…
-
11
votes1
answer165
viewsA: How does the "+" operator work in Javascript?
Not a bug. This is something expected from the language. The operator + is specified so that it can act as a unary operator or as a binary operator. Operator + unary If you are in the context of…
-
5
votes3
answers4625
viewsA: toLocaleString R$ Brazilian
With the introduction of the API Intl, the toLocaleString can no longer be used, in favor of this new interface, much more complete. An example: const number = 1234567.89; const formatter = new…
javascriptanswered Luiz Felipe 32,886 -
5
votes3
answers230
viewsA: Code shortcut for multiple git commands
As placed by another answer, you can use the command alias. However, this approach only allows you to create them in environments that have this command. Windows, for example, would be out. However,…
-
2
votes1
answer35
viewsA: Input input problems directly via browser console (Knockoutjs)
In the example you passed, Knockout will reprint the value on the screen whenever one of the fields undergoes the event change. So, if you want, using native browser Apis, to update the value of one…
-
3
votes2
answers707
viewsA: Get maximum, average and minimum value on a JSON of an object array
You can wear a bow for to add up all wages and then divide that total by the number of records. So: const lista = [ { nome: 'Marcelo', salario: 3200.0 }, { nome: 'Washington', salario: 2700.0 }, {…
-
2
votes1
answer535
viewsA: Formatting value with Numeraljs
In Javascript, as there is only one numeric type (excluding the bigint), there is no proper distinction between a int and a float. Therefore, 20.00 is the same thing as 20. So on your call to…
-
8
votes3
answers4467
viewsA: How to take part of a String up to a specified character?
You can use a regular expression to do this: const string = '99 troços'; const [, match] = string.match(/(\S+) /) || []; console.log(match); In the above regular expression, we create a capture…
javascriptanswered Luiz Felipe 32,886 -
14
votes2
answers286
viewsA: Why does the exchange of values via de-structuring not work if we do not use semicolons?
It is precisely because of this type of thing that the semicolon should always be used. To avoid this type of error in the code. It’s a kind of laziness that can cause mistakes. In Javascript, every…
-
24
votes5
answers582
viewsA: What is a Webhook?
Webhooks are basically a means of communication between your applications. With them, an application is able to send data to other applications. Thus, webhooks send data through the event of a…
terminologyanswered Luiz Felipe 32,886 -
2
votes1
answer458
viewsA: how to list github repositories within an account that has a given topic
You can use the Search API, using the parameter q to formulate darlings more advanced. For example, the following endpoint will return all repositories in the Typescript language to the lffg user:…
-
3
votes2
answers1064
viewsA: Spacing in the JSX
You can print a string with a space ({' '}) to give one space. const App = () => ( <React.Fragment> <strong>Sem</strong> <em>Espaços</em> <hr />…
-
14
votes3
answers603
viewsA: Why is it allowed to delete elements from an array defined as const?
As stated in summary section of the documentation of const: To statement const creates a variable whose value is fixed, that is, a read-only constant. This does not mean that the value is immutable,…
-
4
votes1
answer83
viewsA: Get value of Children and props in React
Em React, children is always a prop. Behold: function App(props) { console.log(Object.keys(props)); // Veja que `children` é uma prop. return <div>{props.children}</div>; }…
-
9
votes1
answer1809
viewsA: How to concatenate object properties with Javascript?
There are several ways to do this. Below I will list three different cases. Use the scattering syntax (Operator spread) If you are in an environment that the support, you can use the scattering…
-
4
votes2
answers138
viewsA: Get object inside an array that has the lowest value in a specific Javascript key
The simplest way is to use a loop for for this. In this way, we will create a variable to store the object that satisfies our needs. At each iteration we will check whether the object of the current…
-
0
votes1
answer62
viewsA: How to export the contents of a promisse that is in a module to another module?
In short, you cannot export the resolution (or rejection) value of the promise. To learn more about why, read this answer. Thus, an option is to export the Promise, and use the then and/or catch in…