Javascript Object Structure Without Key

I am trying to generate an object structure like so:

{nums: {500: 0, 600: 0}}

I have a function that loops and returns numbers as shown in object: 500 & 600. However,

No matter what I try to create an object structure like the above, it does not work.

This is what I have an array of object as follows :

 const scores = [ {score: 500}, {variant_id: 600} ]

How can I loop through the scores array of object and get a structure like:
Number 0 in this example as a value that will be applicable to all scores.

 {nums: {500: 0, 600: 0}}

What I have done is:

  let filteredScores = [];
  for (let i = 0; i < scores.length; i++) {
            const element = scores[i];
            filteredScores.push(element);
  }

However, this does not lead to the desired results.

Any insights or input is much appreciated!

Convert this JavaScript to Jquery [closed]

Here is what I need to convert. Any help would be greatly appreciated! TIA!

document.getElementById("color1").addEventListener("click",
            function() {
                document.getElementById("JS1").style.backgroundColor = 
                    document.getElementById("color1").value;
            });

Here is what I’ve tried so far.

$('#color1').on('click',function(){
            $('#JS1').css('background-color',$('#color1').val());
                });
            

Cant enable button java script [closed]

I want to make an input bar and search button where the search button is only enabled if there is any character in the input bar. So the button is disabled but when I type in the input, it doesn’t get enabled as it should.

    <!DOCTYPE html>
        <html lang="en">
        <head>
           <meta charset="UTF-8">
           <meta http-equiv="X-UA-Compatible" content="IE=edge">
           <meta name="viewport" content="width=device-width, initial-scale=1.0">
           <title>Document</title>
           <script>
              document.addEventListener('DOMContentLoaded', function(){
                 // by default search button is disabbled
                 document.querySelector('#search-button').disabled=true;
                 
                 documnet.querySelector('#search-bar').onkeyup = () => {
                    document.querySelector('#search-button').disabled = false;
                 }
              })
           </script>
        </head>
        <body>
           <form>
              <input id='search-bar'>
              <button id='search-button'>submit</button>
           </form>
        
        </body>
        </html>

any idea how to track a div dynamic Hight increase during an iteration?

Any idea how to track a div dynamic Hight increase during an iteration?
my issue here is I am getting the total height of the items rather than the height being increased on every iteration?

{items.map((item) => {
                if (document.getElementById('divtotrack')) {
                  let clientHeight = document.getElementById('divtotrack')!.clientHeight;
                }
                return (
                  <div>
                    <item
                      key={item.id}
                      id={item.id}
                      content={item.content}
                    />
                  </div>
                );
              })}
            </div>
          </div>

Adding Chart.JS time cartesian (time.unit: second ) xAxes only shows 1 second difference in C#

I have 3 sets of data that have a timestamp (x) and value (y). I have tried to use guides and documentation to try to use the options scale xAxes type: “time” unit seconds. The graph shows nothing but y values on the y axes, labels and a 1 second difference on the x axes.
My code.
Basically, when i add the option to set the unit to seconds my chart breaks. I have no idea why.
Any suggestions would be helpful.

   <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.bundle.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/chart.js/dist/chart.min.js"></script>
   <script src="https://cdn.jsdelivr.net/npm/chartjs-adapter-date-fns/dist/chartjs-adapter-date-fns.bundle.min.js"></script>

    <div class="chartBox">
        <canvas id="myChart"></canvas>
    </div>
    <script>
        const ctx = document.getElementById('myChart').getContext('2d');
        const myChart = new Chart(ctx, {
            type: 'line',
            data: {

                datasets: [{
                    label: 'Melt Gas',
                    data: [{x: '2021-12-6 T 4:42:51' , y:43.450000},
{x: '2021-12-6 T 4:47:51' , y:44.440000},
{x: '2021-12-6 T 4:52:51' , y:45.280000},
{x: '2021-12-6 T 4:57:51' , y:45.940000},
{x: '2021-12-6 T 5:2:51' , y:46.710000},
{x: '2021-12-6 T 5:7:51' , y:47.480000},
{x: '2021-12-6 T 5:12:51' , y:48.140000},
{x: '2021-12-6 T 5:17:51' , y:48.910000},
{x: '2021-12-6 T 5:22:51' , y:49.690000},
{x: '2021-12-6 T 5:27:51' , y:50.350000},
{x: '2021-12-6 T 5:32:51' , y:51.130000},
],
                    backgroundColor: [
                      'rgba(54, 162, 235, 0.2)'
                    ],
                    borderColor: [
                        'rgba(54, 162, 235, 1)'
                    ],
                    tension: .4
                }, {label: 'Spin Gas',
                    data: [{x:'2021-12-6T4:44:5' , y:7.470000},
{x:'2021-12-6T4:49:5' , y:7.680000},
{x:'2021-12-6T4:54:5' , y:7.820000},
{x:'2021-12-6T4:59:5' , y:7.960000},
{x:'2021-12-6T5:4:5' , y:8.100000},
{x:'2021-12-6T5:9:5' , y:8.240000},
{x:'2021-12-6T5:14:5' , y:8.360000},
{x:'2021-12-6T5:19:5' , y:8.490000},
{x:'2021-12-6T5:24:5' , y:8.630000},
],
                    backgroundColor: [
                        'rgba(255, 206, 86, 0.2)'
                    ],
                    borderColor: [
                        'rgba(255, 206, 86, 1)'
                    ],
                    tension: .4
                }, {label: 'T5 OVEN Gas',
                    data: [{x:'2021-12-6T4:44:11' , y:23.140000},
{x:'2021-12-6T4:49:11' , y:23.520000},
{x:'2021-12-6T4:54:11' , y:24.000000},
{x:'2021-12-6T4:59:11' , y:24.390000},
{x:'2021-12-6T5:4:11' , y:24.770000},
{x:'2021-12-6T5:9:11' , y:25.130000},
{x:'2021-12-6T5:14:11' , y:25.550000},
{x:'2021-12-6T5:19:11' , y:26.030000},
{x:'2021-12-6T5:24:11' , y:26.440000},
{x:'2021-12-6T5:29:11' , y:26.730000},
{x:'2021-12-6T5:34:11' , y:27.000000},
{x:'2021-12-6T5:39:11' , y:27.310000},
{x:'2021-12-6T5:44:11' , y:27.590000},
{x:'2021-12-6T5:49:11' , y:27.970000},
{x:'2021-12-6T5:54:11' , y:28.430000},
],
                    backgroundColor: [

                        'rgba(153, 102, 255, 0.2)'
                    ],
                    borderColor: [
                       'rgba(153, 102, 255, 1)'
                    ],
                    tension: .4
                }],
            },
            options: {
                scales: {
                    xAxes: @*[ added/removed*@{
                        type: "time",
                        time: {
                            unit: "second", //when i this section the graphs breaks.
                        },
                        parser: true,//also have removed this/added
                    }@*] added/removed*@,
                    y: {
                        beginAtZero: false
                    }
                }
            }
        });
    </script>

JavaScript – convert text from API response to JavaScript array

I’m receiving some text from an API with JavaScript.

I need to convert this text into a JavaScript array to use it. Currently I can get the text but I need an extra step to convert it into a JavaScript array so I can console.log() it.

// API response. Note there are no quotes around it, it is exactly as is below
//["hi ",["hi medicaid","hi mama","hi in french","hi in spanish","hi in japanese","hi there","hi mom","hi in chinese"],"search"]

const response = await fetch("/autocomplete.php", {
     method: "POST"
});

const data = await response.text();
        
// Breaks down here
console.log(data[1]); // This logs: "

Cash App Phone Number (I866꞊978꞊5841) Cash App Customer Service Number

Many of you might have received a call from cash app phone number +1-866-978-5841, or you might have seen the number on a financial transaction or a credit card statement. If you have seen this number, then you must know that is from the company Square. Square permits small businessmen to get credit cards with the help of mobile devices. The company also owns an app named Cash App that allows you to send money to your friends or family members by using mobile devices. Square allows small businessmen to process credit cards. As a result, you will see that the name of the company and the cash app customer service number +1-866-978-5841 will be found on a transaction. This might be because this transaction was done by a small business owner.

Logical grouping in HTML for results pulled from object

I am successfully iterating through an object/array from an API and am able to take three parameters, Author/Title/Description, and place results from each parameter into their own lists. In other words, all Authors from the array are being placed in html into one list, all Titles are placed into one list, all descriptions are placed into one list.

How can I group the results logically, as in, for each book have the results Author/Title/Desc placed into one area on the page …(div?)?

const searchButton = document.getElementById('searchbtn')
const form = document.getElementById('myform')
const author = document.querySelector('.author')
const title = document.querySelector('.title')
const description = document.querySelector('.description')

document.addEventListener("DOMContentLoaded", () => {
    searchButton.addEventListener('click', e => {
        e.preventDefault()
        const inputSearch = document.getElementById('books').value
        const bookUrl = ('https://www.googleapis.com/books/v1/volumes?q=' + inputSearch)
        fetch(bookUrl)
        .then (res => res.json())
        .then (obj => {
            obj.items.forEach((book, index) => {
                const listAuthor = document.createElement('li')
                const listTitle = document.createElement('li')
                const listDescription = document.createElement('li')
                listAuthor.innerText = book.volumeInfo.authors
                listTitle.innerText = book.volumeInfo.title
                listDescription.innerText = book.volumeInfo.description

                author.appendChild(listAuthor)
                title.appendChild(listTitle)
                description.appendChild(listDescription)
            })
            form.reset()
        })
    })
})

How can i show the items for a specific category

Hi i want to show the items for a specific category only, so when the user is on the html page they can pick a category and then it should show the items for that category only, its the “vareKategori” where you can choose.[See the frontend her][1]
for now i can display all the items but i can’t get products for only one category. It would meen so much if somebody could show me how to do it, thx.

Please help,its for an exam project.

this is my code for now:
// Jeg laver en function som tager userinputtet fra det de skriver. Det gør jeg både for nyt userID og nyt password



document.addEventListener("DOMContentLoaded", (event) => {
  document.getElementById("form").addEventListener("submit", (event) => {
    event.preventDefault();

    const varer = document.getElementById("varer").value;
    const pris = document.getElementById("pris").value;
    const vareKategori = document.getElementById("vareKategori").value;
    const billede = document.getElementById("billede").value

    const opretVare = {
      varer: varer,
      pris: pris,
      vareKategori: vareKategori,
      billede: billede
    };

    fetch("http://localhost:8200/varer/createvarer", {
        method: "POST",
        headers: {
          'Accept': 'application/json',
          'Content-Type': 'application/json'
        },
        body: JSON.stringify(opretVare),
      })
      //converter det til Json
      .then((response) => response.json())
      .then((response) => {
        if (response) {
          location.href = "/varer.html";
        }
      })
      .catch(() => {
        window.alert("Der skete en fejl");
      });
  });
});


async function getGoods() {
  const response = await fetch("http://localhost:8200/varer/getproducts")
  const result = await response.json()
  return result
}

async function deleteGoods(id) {
  const response = await fetch("http://localhost:8200/varer/getproducts/" + id, { 
    method: 'DELETE'
  })
  const result = await response.json()
  return result
}

function renderTable(goods) {
    const table = document.getElementById('varerTable');
    let tableHtml = `
      <tr>
      <th>
      <label Varekategori:</label>
      <select name="kategori" id="kategori">
          <option value="mad">Mad</option>
          <option value="drikkelse">Drikkelse</option>
      </select>
      </th>
      
      <th>Vare</th>     
       <th>Pris</th>
        <th>Billede</th>
      </tr>`;
    for (const row of goods){
      tableHtml += `
        <tr>
          <td>${row.vareKategori}</td>
          <td>${row.varer}</td>
          <td>${row.pris}</td>
          <td><img src="${row.billede}" style="height:100px;width000px;"</td>
          <td><button onclick = "handleDelete(${row.id})"> Delete </button></td>
          <td><button onclick ="toDo"> Edit </button></td>
        </tr>
      `;
    }
    table.innerHTML = tableHtml;
}

async function handleDelete(id) {
  try {
    await deleteGoods(id)
    const goods = await getGoods()
    renderTable(goods)
  } catch(err) {
    console.error(err)
  }  
}

async function handleLoad() {
  try {
    const goods = await getGoods()
    renderTable(goods)
  } catch(err) {
    console.error(err)
  }  
} 
document.getElementById("clickMe").addEventListener('click', handleLoad);

routes

router.put("/opdater_products/:varer", (req, res)=>{
  let category = req.params.varer;
  if(products[category]){
    products[category] = req.body.pris;
    res.status(200).json({[category]:products[category]});
  }
  else{
    res.send(404)
  }
  });

model

class Goods {
    constructor(varer, pris, vareKategori, billede) {
      this.varer = varer;
      this.pris = pris;
      this.vareKategori = vareKategori;
      this.billede = billede;
    }
  }
  module.exports = Goods;

understanding border-images to fill perfectly without streching

I try to use an image as a border image for a div.

The div width and height changes (I don’t know how the dimensions will be)

The border-images width and height changes (I don’t know how the dimensions will be)

I really tried to understand what is slicing doing, but I can’t get a dynamic formula so that any given border-image will look good for any given div size (look good = not sctreched, filled,nicely repeated as long the border-image is seamless)

for a given border-image pineapple.png with a dimension 1584x1200px => 105 133 round looks good, but how do I get this magic numbers? What numbers use there for slice to get a crispy border-image regarding not violating its proportions? Is it depending on the div size AND the border-image size?

div{
background:red;
height:100px;
width:400px;
border: solid 5vmin transparent;
border-width: 5.67909vmin;
border-image: url(https://cdn.dribbble.com/users/4297010/screenshots/7740500/media/7c2554596ed3249419127182c5199e65.jpg)105 133 round;
}
<div>
</div>

Javascript solutions are also much appreciated

I would like to add a search box by date.to my table using mysql php

I have a table associated with a database mysql , All I want is to add a search box by date ,Although I have tried many methods, but unfortunately all of them did not work for me as I should This is my code :

    <form action="" method="GET"">
<input type="date" name="search" class="form-control" placeholder="Start"  >
<button type="submit" class="btn btn-primary">Search</button>
</form>


    function getRecords($params) {
            $rp = isset($params['rowCount']) ? $params['rowCount'] : 10;
            
            if (isset($params['current'])) { $page  = $params['current']; } else { $page=1; };  
            $start_from = ($page-1) * $rp;
            
            $sql = $sqlRec = $sqlTot = $where = '';
            
            if( !empty($params['searchPhrase']) ) {   
                $where .=" WHERE ";
                $where .=" ( fullname LIKE '".$params['searchPhrase']."%' ";    
                $where .=" OR email LIKE '".$params['searchPhrase']."%' ";

                $where .=" OR phone LIKE '".$params['searchPhrase']."%' )";
                
            
                
           }
           if( !empty($params['sort']) ) {  
                $where .=" ORDER By ".key($params['sort']) .' '.current($params['sort'])." ";
            }
           // getting total number records without any search
            $sql = "SELECT * FROM `api` where  DATE_FORMAT(created_at, '%Y-%m-%d') = DATE_SUB(CURRENT_DATE(),INTERVAL 1 DAY)";
            $sqlTot .= $sql;
            $sqlRec .= $sql;
            
            //concatenate search sql if value exist
            if(isset($where) && $where != '') {

                $sqlTot .= $where;
                $sqlRec .= $where;
            }
            if ($rp!=-1)
            $sqlRec .= " LIMIT ". $start_from .",".$rp;
            
        

How do you handling floating point arithmetic when using the ParseObject.increment() function

In javascript, we know that some floating point arithmetic will result in values that contain a very small remainder. for example if I open my console and do this math I get this result as seen here

enter image description here

Typically one must know to round after doing these operations. When using parse, and using the increment function. If I have a column called Quantity in my DB and it currently has a value of 6.5 and I call myobject.increment("Quantity", -4.1) we end up with an unrounded value in the DB. the use of increment is required here as many entities may be adjusting this column at or near the same time, so race conditions are a concern.

since the arithmetic happens under the hood, how does parse expect one to handle cases like I mentioned above.

How to check the URL of a page using JavaScript

How would I make a script that detects the current URL of the page? Here is what I want it to do:

When the script is on example.com it lets the page load normally.

When the script is on coolsite.com it replaces the content of the page with a note showing a link to example.com

How would I do that? Is there a function that detects the location of the window? I can put it in a <script> element or a separate JavaScript file.

Thank you for any help!