Posts by bfavaretto • 64,705 points
902 posts
-
26
votes7
answers620
viewsA: How to access a circular array?
WARNING Rereading this answer two years later, NAY It seems to me a good use case for an iterator... It has no need, it is only syntactic firula and probably has an impact on performance. I must…
-
1
votes1
answer42
viewsA: How to auto-complete a value without overloading the database
In such cases, what is done is to limit the amount of requests to the server. The traditional technique for this is the debauchery of the events of keyup of the browser in the search input. Instead…
-
0
votes1
answer401
viewsA: Webpack ( Error: net::ERR_FILE_NOT_FOUND)
Use a web server (can be a service on your computer, does not need to be remote). The access by the file:/// protocol you are using has a number of restrictions. You need to access via http or…
javascriptanswered bfavaretto 64,705 -
2
votes1
answer101
viewsA: How to call a js function in html
You are mounting HTML inside a string template, so whatever you have of JS in the middle, enter ${}, will be executed. You must change: ${editar(cellData,row)} for editar(${cellData},${row}). And…
javascriptanswered bfavaretto 64,705 -
1
votes1
answer86
viewsA: Do we need to call cancelAnimationFrame for frames prior to the current requestAnimationFrame?
First you need to understand what your second example, the simplest, does, then you’ll understand that the first example doesn’t make sense. After reading my answer, I suggest you reread the article…
-
11
votes1
answer114
viewsA: Why is 16 equal to 020 in Javascript?
The number 020 is being interpreted as octal - i.e., base 8, using the digits 0 to 7 to represent the values. In Javascript, literal values started with zero are interpreted as octal, except in…
-
3
votes1
answer53
viewsA: Remove array quotes with two positions
Do you want to convert all values into number? You can use the method map of the array for this: let lista = ["1", "2"].map( s => Number(s) );…
javascriptanswered bfavaretto 64,705 -
5
votes3
answers1024
viewsA: When and how to use instanceof and typeof operator in Javascript
The typeof and the instanceof are complementary and have different syntaxes. The typeof checks the primitive type of a value, and always returns one of the following strings: "undefined" "boolean"…
-
17
votes3
answers681
viewsA: What makes cache invalidation a difficult solution?
This response is based on my personal experience, what I learned in practice, and includes conceptual inferences from that experience. See detailed point-to-point examples in Anderson Carlos Woss…
-
4
votes1
answer79
viewsA: Can someone explain that code to me?
You pass T for the function AND: AND(T, T) And she invokes T passing by b (in this case also equal to T) and F: var AND = function (a, b) { return a(b, F); }; The execution logic of this whole code…
-
3
votes2
answers152
viewsA: receiving null or void field
If I understand correctly, just include single quotes when the value is not empty: $dataBatismo = empty($Membro->getDataBatismo()) ? "NULL" : "'" . $Membro->getDataBatismo() . "'"; NOTE: I…
-
5
votes1
answer56
viewsA: How to return table values using the SUM() function?
If I understood what you want, it doesn’t need grouping or summation, it would be something like this: SELECT tbCliente.ClienteID, tbCliente. ClienteNome, tbPagamento.PagamentoValor FROM tbCliente…
-
2
votes1
answer146
viewsA: Can I create mobile apps (.apk and .obb) using Electron?
No, this is not possible. Electron is a tool for creating desktop applications exclusively. For mobile there are other similar solutions, such as Phonegap.
-
3
votes3
answers104
viewsA: Javascript functions sharing information?
Responding literally to what you said: I wonder if it is possible for two Javascript functions to share information that is in one of them. Yes, it is possible. There are basically two mechanisms…
javascriptanswered bfavaretto 64,705 -
1
votes2
answers246
viewsA: Create a dynamic object recursively
If I understand the question correctly, and if it is to follow the order of the properties as it is in the array (in your example there is an inversion), nothing recursive is needed, just a loop.…
-
5
votes2
answers706
viewsA: I calculate value with Comma with Vue.JS
Change the comma by a dot: <p>{{ valor.replace(',', '.') - 2 }}</p> I recommend to create a computed property of Vue and replace there, not to dirty your view. Another thing, this will…
-
5
votes2
answers417
viewsA: Count with null value return zero
You can use a conditional sum combination to sum zero or one as the case may be. Example compatible with various bases: SELECT SUM(CASE WHEN a.pedido IS NULL THEN 0 ELSE 1 END) AS total Example for…
-
5
votes1
answer46
viewsA: Doubt about getter in Javascript
is only used to work with the variable value while maintaining the original value of the variable or would have more application? No, a getter can return something only based on the state of…
javascriptanswered bfavaretto 64,705 -
5
votes1
answer57
viewsA: PHP xf0 represents 0xF0?
These are different things. The first example is a string, and the escape notation \xHH represents the hexadecimal code of a character. Already the 0xF0 is a number, integer, represented as literal…
-
14
votes1
answer193
viewsA: What is the purpose of Object.is?
Differences in relation to the operator ===, according to the documentation of the MDN, sane: Object.is distinguishes +0 of -0, but === does not distinguish. Object.is considers two NaN as "equal"…
-
0
votes3
answers80
viewsA: Access to Mysql
The query is failing because you did not pass the connection. As indicated in manual, would look like this: $selecao = mysqli_query($conn, 'SELECT * FROM tabela_precos');…
phpanswered bfavaretto 64,705 -
10
votes1
answer78
viewsA: How does this code break the string into parts?
The functions head and tail make a "smart" use of the operator of spread and the fact that strings allow character-to-character access with the use of brackets. When it is stated that their argument…
javascriptanswered bfavaretto 64,705 -
4
votes1
answer336
viewsA: ::before is not displayed in <img>
There’s no point in using the pseudo-element ::before with <img>, because this tag has no content (no closing tag). Despite the confusing name, the ::before creates a pseudo-element before of…
-
4
votes2
answers213
viewsA: Difference between click, bind, live, delegate, Trigger and on functions?
The methods live and delegate are old forms of event delegation, and have already been removed from the library. Currently you should delegate with the syntax: $('seletor').on('evento',…
-
1
votes1
answer1056
viewsA: Minutes, Seconds and Milliseconds with setInterval
if I put instead of 1000 put 1 the function will run every millisecond In theory yes, but in practice no. The Javascript engine does not account for running 1000 times per second the functions…
-
5
votes1
answer47
viewsA: Transform this jQuery code into pure Javascript
Your mistake is that there is no direct equivalent of .css(...) in pure javascript. You need some kind of loop upon the return of the document.querySelectorAll(".social li a"). You can’t change the…
javascriptanswered bfavaretto 64,705 -
1
votes1
answer50
viewsA: Catch id auto increment of two joined tables (INNER JOIN)
Ideally you list the columns that matter one by one, instead of using *. There you can define a alias for each one if necessary. For example: SELECT notification.id AS notification_id, topicos.id AS…
-
8
votes1
answer118
viewsA: What is Typedarray? What are the advantages of using them compared to the traditional Array?
In which cases should I use Typedarray instead of the standard Javascript array? Would you like examples To MDN documentation gives 3 examples: the Apis of FileReader, of XMLHttpRequest and of…
-
0
votes2
answers22
viewsA: Doubt about ajax (javascript)
Use & to separate the parameters: $.ajax({ url: 'api.php?line=' + value + '&other=' + outro, type: 'GET' }); If many values, or long values, use POST instead of GET.…
-
2
votes2
answers122
viewsA: Pass Cpf to a javascript function
From what I see in your Razor template, the field id is cpf. So you can take the field and its value from within the function, based on that id. It doesn’t make sense for this function to return…
-
9
votes3
answers285
viewsA: html/javascript clock does not appear
Always open your browser console to see errors! There are several syntax errors in your code: new Data() instead of new Date(). getElementByid instead of getElementById. function Relogio{ should be…
-
10
votes1
answer812
viewsA: What does "Tree-Shaking" mean?
Actually in general it applies to Javascript, or more precisely to the generation of "optimized" Javascript code. The original code can be in Typescript, Javascript, or other language. According to…
-
2
votes4
answers4547
viewsA: How to Merge 2 or more Json Objects into Only 1
Well they look like two arrays. In that case, this would be enough: var arr1 = [{nome: "f1"}, {nome: "f2"}]; var arr2 = [{nome: "f3"}, {nome: "f4"}]; var junto = arr1.concat(arr2);…
-
5
votes2
answers209
viewsA: What’s the Weakmap object for?
I recommend reading the question about Map first. The kind WeakMap works exactly like the Map, with the following main differences: Only accepts objects as key It is not enumerable, that is, it does…
-
2
votes1
answer69
viewsA: overflow Hidden with float left
This has historical roots If you’re looking for an explanation of the logic behind this behavior, forget it - and that goes for many other CSS questions. The oldest reference of this I found in the…
-
4
votes1
answer108
viewsA: SQL with empty Join
When you use LEFT JOIN but puts related table conditions in the WHERE, Join may end up behaving like INNER. Do so: SELECT `turmas_has_estudantes`.`id`, `turmas_has_estudantes`.`numero`,…
mysqlanswered bfavaretto 64,705 -
5
votes1
answer52
viewsA: Push a tag to the remote
Use, as documented: git push origin <nome-da-tag> In git, tags and branches are very similar, both pointers to specific commits. Hence, the syntax for push is the same.…
gitanswered bfavaretto 64,705 -
2
votes1
answer90
viewsA: How to Return Existing Primary Key Error in PHP/Mysql?
Use the function mysqli_error(). I take this opportunity to correct a logic error of your code, your if($inclui) will always turn out true. $sql="INSERT INTO DTC…
-
2
votes4
answers39
viewsA: Knowing which index of array values gives "match" with variable
If the two arrays are always the same size, loop a counter based on one of them, and inside check the value of the two. For example: var cores = ["Amarelo", "Amarelo", "Amarelo", "Preto", "Preto",…
-
0
votes1
answer104
viewsA: Ajax does not enter Success
If the function beforeSend not return true, the request is aborted, as the documentation says. Do so: beforeSend: function () { $("#btnEvniar") .prop('disabled', true) .click(JaClicouProc(3,this));…
ajaxanswered bfavaretto 64,705 -
2
votes1
answer389
viewsA: How to make an INNER JOIN in a single table with 3 keys?
From what I understand, all it takes is one JOIN: SELECT ny.*, ms.* FROM z_quotes ny INNER JOIN z_quotes ms ON ny.origem = ms.origem AND ny.papel = ms.papel AND ny.mercado = ms.mercado WHERE…
-
4
votes4
answers320
viewsA: Check if a string is only composed of 0
I would force a conversion to number with the operator +, then would check if gave 0. It’s quite simple: var palavra = '00000'; var palavra2 = 'a00a0'; console.log(+palavra === 0);…
javascriptanswered bfavaretto 64,705 -
1
votes1
answer77
viewsA: Is it possible to add an event listener to the url?
Example of use of the event hashchange: var out = document.getElementById('output'); window.addEventListener('hashchange', function(e) { out.innerHTML = 'hash atual: ' + window.location.hash; });…
-
7
votes2
answers381
viewsA: Does Javascript not work in Safari/Edge?
Browsers have variations on the date formats they can interpret. The code you linked uses the following: var countDownDate = new Date(m+" "+d+","+a).getTime(); This format is not very usual and does…
-
1
votes2
answers49
viewsA: problems with color exchange through javascript
You are redeclareting the variable cor within the function, and thereby lose access to the external scope variable. Do so (I took the opportunity to remove an unnecessary repetition): var timer =…
-
2
votes3
answers69
viewsA: Add items to the beginning of a vector without affecting existing values
If you already know right away that you need 18 items, just put the first 15 on index 3 on, and then the others at the beginning. #include <stdio.h> int main(void) { int v[30]; int i; //…
-
1
votes1
answer17
viewsA: Get input ids using for no js
You’re trying to catch the innerHTML of the inputs when should take the value: n[i] = document.getElementById(inputId).value;
javascriptanswered bfavaretto 64,705 -
0
votes2
answers173
viewsA: Typescript variable inside function allocates information outside of it it is empty
I think that function subscribe is asynchronous. This means that your alert from the outside executes before of you changing the value of y. You can only use y after having assigned a value within…
javascriptanswered bfavaretto 64,705 -
3
votes4
answers71
viewsA: Repeat zebra style color only 5 by 5
You are changing the color in every loop iteration, but only need to change when it is multiple of 5. One condition is missing. var collection = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15];…
-
2
votes1
answer9463
viewsA: Line break with css without <br>
Use overflow-wrap: break-word; Or word-break: break-word; References https://developer.mozilla.org/en-US/docs/Web/CSS/overflow-wrap https://developer.mozilla.org/en-US/docs/Web/CSS/word-break…