I have a data structure of an array and objects, How can I extract the information, or in other words access a specific or multiple values (or keys)? [closed]

 [
  [
    { title: 'Director of Sales', id: 1 },
    { title: 'Enterprise Account Executive', id: 2 },
    { title: 'Mid-Market Account Executive', id: 3 },
    { title: 'General Council', id: 4 },
    { title: 'Senior Engineer', id: 5 },
    { title: 'Junior Engineer', id: 6 }
  ]
]

Every time I try and grab the “title” key or all the title keys it gives me [object Object]

Sort Array with String Dates (JavaScript)

I have this piece of code for sorting:

compareDates(a: string, b: string, isAsc: boolean) {
    // splitting the string after on dot, because the date string is like: 14.06.2022
    var d1Splitted = a.split('.');
    var d2Splitted = b.split('.');
    const d1 = Date.parse(d1Splitted[2] + '-' + d1Splitted[1] + '-' + d1Splitted[0]);
    const d2 = Date.parse(d2Splitted[2] + '-' + d2Splitted[1] + '-' + d2Splitted[0]);

    return isAsc ? Number(d1) - Number(d2) : Number(d2) - Number(d1);
  }

wenn I sort a list by date I get the well sorted list, but after few times of clicking on sort button I get this:
enter image description here

“cannot find module” with import but not with require

I am trying to setup the mailchimp sdk in my app and the docs say to import it like so:

const mailchimp = require('@mailchimp/mailchimp_marketing');

The path works fine here, but i get this lint error:

ESLint: Require statement not part of import statement.(@typescript-eslint/no-var-requires)

So I converted this to the regular import (both manually and letting my ide automate the conversion) like this:

import mailchimpFactory from ‘@mailchimp/mailchimp_transactional/src/index.js’;

The problem now is that it can’t find the module.
I don’t know how to import this package without using require, and I really don’t want to go against the entire projects standards just for one single import.

Mobile View is Scrunching Pictures

I am working on a portfolio using basic html, css, js. I am adapting a template and will be making the changes that suit my needs. On pc, the web page loads fine. However, on my iPhone, the pictures within the portfolio section always load scrunched on top of one another and I cant seem to figure out the root cause of the issue.

The site is deployed here: https://venerable-dasik-8f5a93.netlify.app/

Is this something to do with the layout? The number of pictures? Is there a workaround?

select dropdown in JavaScript

I am selecting 2nd option in this dropdown using JavaScript but oninput event not working which is present in select tag.

document.getElementById("EQUIPMENT_DETAILS_DAILY_CHECKLIST").value = "ANBG_ACCH401";
<select oninput="this.className = ''" class="" name="EQUIPMENT_DETAILS" id="EQUIPMENT_DETAILS_DAILY_CHECKLIST">
  <option value="">SELECT</option>
  <option value="ANBG_ACCH401">ANBG-ACCH401</option>
  <option value="ANBG_ACCH402">ANBG-ACCH402</option>
</select>

Mute audio output of an iFrame with Js/Ts

I want to mute an iFrame audio output in my Angular App. I tried some solutions, but they didn’t work for me.

Here is my iFrame:

<iframe allow="camera; microphone; display-capture; autoplay; clipboard-write" src="https://meet.jit.si/a#jitsi_meet_external_api_id=0&amp;config.prejoinPageEnabled=false&amp;config.disableDeepLinking=true&amp;interfaceConfig.TOOLBAR_ALWAYS_VISIBLE=true&amp;interfaceConfig.TOOLBAR_BUTTONS=%5B%5D&amp;userInfo.displayName=%22Gustavo%20Paciente%22&amp;appData.localStorageContent=null" name="jitsiConferenceFrame0" id="jitsiConferenceFrame0" allowfullscreen="true" style="height: 778px; width: 1350px; border: 0px;"></iframe>

And here are the “solutions” I’ve already tried:

1 – In this case, the volume attribute is set to html, but the audios it no muted:

const iframe: any = document.getElementById('jitsiConferenceFrame0');
iframe.setAttribute("volume", "0");

2 – In this case, the “contentDocument” is null

const iframe: any = document.querySelector('iframe[id="jitsiConferenceFrame0"]');
iframe.contentDocument.getElementById("muted").checked = true;
iframe.contentWindow.speaker[0].muted = true;
iframe.contentWindow.speaker[1].muted = true;

3 – In this case, “iframe.contentDocument” (line 2) is null and “iframe.contentWindow” exists, but “iframe.contentWindow.document” (line 2) is also null.

var iframe = document.getElementById('iframeId');
var innerDoc = iframe.contentDocument || iframe.contentWindow.document;
var MediaSource = innerDoc.getElementById('mediaElem');
MediaSource.muted=true;

I think I’m not so far of getting it solved, but still need some help. How to solve it?

EDIT Here is my iframe object

onChange Event not Triggered in React JS

 <div className="col-md-2">

                  {
                   
                      authorities.map((data,index) => (
                        <>
                          <div key={index} style={{ display: "flex" }}>
                            <div className='col-md-10 mx-0 mt-2'>
                              <Input type={"checkbox"}
                                checked={data?.isChecked || false}
                                name={data.authority}
                                onChange={(e) => console.log(e)}
                                className="form-control"
                                style={{ cursor: "pointer", paddingLeft: "1rem" }}
                              /></div>
                            <div>
                              <label style={{ cursor: "pointer" }} htmlFor={data.authority} className="col-md-50 col-form-label"> {data.authority}</label>
                            </div>
                          </div>
                        </>
                      )) 
                  }

                </div>

I want to check multiple checkbox but can’t triggered onChange Event. No event display at console
please solve my doubt.

What are the steps to create a custom Booking-Tool using MS Graph in PHP/JS? [closed]

I’m trying to create a custom booking tool and I wanna use the API calls from MS Graph. Unfortunately I can’t find any proper tutorial or example code to make this tool in PHP or JS.

The customer should be able to choose a desired free date and time in the MS Agenda and should be able to book this appointment. The appointment should then be displayed in the boss’s MS Agenda.

I really have no clue how to do this. I have searched hard on the internet, but there is no short guideline.

What I know so far is that first there has to be authentication/authorization by the email with the MS Agenda, after that API calls can be made using MS Graph Explorer. Still no clue how to go about this…

Can anyone help me with this? It can either be in native Jquery/Javascript or Native PHP.

Horizontal Scrolling With multiple images

I stumbled across this codepen and was wondering if there is away to have multiple images, side by side, in the horizontal scroll section. So in stead of just one div with bg-iamge, maybe just simple img tags inside the div? Would it be possible to embed videos in there as well?

Any help is appreciated, I couldn’t figure it out myself. 🙁

See codepen here: Link

<h1 class="header-section">Scroll down to see a horizontal scroll section</h1>


<div class="massiveImage"></div>

<h1 class="header-section">Now we're back to regular scrolling</h1>


<header>
   <a href="https://greensock.com/scrolltrigger">
     <img class="greensock-icon" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/16327/scroll-trigger-logo-light.svg" width="200" height="64" />
  </a> 
</header>



.massiveImage {
  height: 100vh;
  width: 400vw;
  background-size: cover;
  background-position: center;
}
.header-section {
  padding-bottom: 50vh;
  margin-bottom: 0;
}


gsap.registerPlugin(ScrollTrigger);

gsap.set(".massiveImage", {backgroundImage: `url(https://source.unsplash.com/random/${innerWidth * 3}x${innerHeight})`})

gsap.to(".massiveImage", {
  xPercent: -100, 
  x: () => innerWidth,
  ease: "none",
  scrollTrigger: {
    trigger: ".massiveImage",
    start: "top top",
    end: () => innerWidth * 3,
    scrub: true,
    pin: true,
    invalidateOnRefresh: true,
    anticipatePin: 1
  }
});

How to add point_count divieded by some value to map

Using Mapbox GL JS I want to add to the map the number of markers in a cluster divied by 10.

I can add the point_count and point_count_abbreviated attributes as following:

map.addSource("uploaded-source", {
            type: "geojson",
            data: geoJSONcontent,
            cluster: true,
            clusterMaxZoom: 15, 
            clusterRadius: 50, 
          });

map.addLayer({
            id: "cluster-count",
            type: "symbol",
            source: "uploaded-source",
            filter: ["has", "point_count"],
            layout: {
              "text-field": "{point_count_abbreviated}",
              "text-font": ["DIN Offc Pro Medium", "Arial Unicode MS Bold"],
              "text-size": 12,
            },
          });

How do I add point_count_abbreviated divided by some number to the map?

Unfortunately my JS knowledge is not that advanced, I tried things like:

 "text-field"://{point_count_abbreviated}/10
              //String(Number("{point_count_abbreviated}")/10),
              //"{point_count_abbreviated}".slice(0, -1),
              //String(Number(['/', ["get", Number("{point_count_abbreviated}")], Number(10)]))

form doesnt get submitted after disabling button after submit

Hello there i want my button disabled after the form submitted.
Disabling the button works but it doesnt execute the php code.

I tried different scrips that are posted on the internet but they all do the same: disabling the button without executing the php code. So when form is submitted it needs to echo “test” but it doesnt echo “test”.

Code:


<!DOCTYPE html>
<html lang="en">

<body>
<h1>jQuery - How to disabled submit button after clicked</h1>

<form id="formABC" method="POST">
    <input type="submit" name="submit" id="btnSubmit" value="Submit"></input>
</form>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>

<input type="button" value="i am normal abc" id="btnTest"></input>

<script>
    $(document).ready(function () {

        $("#formABC").submit(function (e) {

            //stop submitting the form to see the disabled button effect
            e.preventDefault();

            //disable the submit button
            $("#btnSubmit").attr("disabled", true);

            //disable a normal button
            $("#btnTest").attr("disabled", true);

            return true;

        });
    });
</script>

</body>
</html>
</body>
</html>

<?php


if (isset($_POST['submit'])) {
    echo "test";
}

?>
</body>
</html>

Why doesn’t my UI properly rerender my deleted object?

I have a parent component that maps over a list state using an Input component

import "./styles.css";
import { useState, useEffect } from "react";
import Input from "./Input";

export default function App() {
  const [list, setList] = useState([{}]);
  useEffect(() => {
    console.log("list", list);
  }, [list]);
  return (
    <div className="App">
      <h1>Hello CodeSandbox</h1>
      <h2>Start editing to see some magic happen!</h2>
      {list.map((_, i) => (
        <div key={i}>
          <Input id={i} setList={setList} />
        </div>
      ))}
    </div>
  );
}

Submitting each Input leaves another Input available for submission. However, when I delete each Input, I see that the data object is gone but the UI doesn’t reflect this.

import { useState } from "react";

const Input = ({ setList, id }) => {
  const [value, setValue] = useState("");
  const [submitted, setSubmitted] = useState(false);
  const handleChange = (event) => {
    const result = event.target.value.replace(/D/g, "");
    setValue(result);
  };
  const handleSubmit = () => {
    setList((list) => [...list, { id: id, total: value }]);
    setSubmitted(true);
  };
  const handleDelete = () => {
    console.log("id", id);
    setList((list) => list.filter((item) => item.id !== id));
  };
  return (
    <div>
      <input
        value={new Intl.NumberFormat("ko-KR", {
          style: "currency",
          currency: "KRW"
        }).format(Number(value))}
        onChange={handleChange}
        type="text"
      />
      {submitted ? (
        <button disabled={value.length === 0} onClick={handleDelete}>
          Delete
        </button>
      ) : (
        <button disabled={value.length === 0} onClick={handleSubmit}>
          Submit!
        </button>
      )}
    </div>
  );
};

export default Input;

I suspect that this is because

  const [list, setList] = useState([{}])

Is initialized with an empty object, and that is causing the problem. However, I need at least one object inside the list state so I can have the initial Input component for submission.

How do I properly delete my Input component?

My codesandbox

navigation bar contents lose all styling after translation

I have ran into a problem, I have managed to translate nav bar. Right now, I have managed to translate all the content of the page but I have a problem which I cannot figure out myself. The problem: When I switch the language of the page from “English” to “Latvian” all leading to other pages and css styling disappears. After the translation the latvian version becomes a plain text in the navbar, but it stays the same in heading and paragraph. Can anyone help me solve the problem?
HTML:

<div class="langWrap">
            <a href='#' language='english' class="active">EN</a>
            <a href='#' language='latvian'>LV</a>
</div>
<div class="content">
    <header id="up">
        <img src="/img/logo.png" alt="QuickSportScoresLogo" class="logo">
        <div class="container">
            <nav>
                <ul>
                    <li class="aboutus"><a href="/">About Us</a></li>
                    <li class="news"><a href="news">News</a></li>
                    <li class="results"><a href="results">Results</a></li>
                    <li class="leagues"><a href="leagues">Leagues</a></li>
                    <li class="login"><a href="login">Profile</a></li>
                </ul>
            </nav>
        </div>
    </header>
    <h1 class="headings"> News</h1>
    <p class="description">Last weekend there were a lot of great games.
    </p>
</div>

JS:

<script>
        const langEl = document.querySelector('.langWrap');
        const link = document.querySelectorAll('a');
        const titleEl = document.querySelector('.headings');
        const descrEl = document.querySelector('.description');
        const aboutUsEl = document.querySelector('.aboutus');
        const newsEl = document.querySelector('.news');
        const resultsEl = document.querySelector('.results');
        const leaguesEl = document.querySelector('.leagues');
        const loginEl = document.querySelector('.login');


        link.forEach(el => {
            el.addEventListener('click', () => {
                langEl.querySelector('.active').classList.remove('active');
                el.classList.add('active');

                const attr = el.getAttribute('language');

                titleEl.textContent = data[attr].headings;
                descrEl.textContent = data[attr].description;
                aboutUsEl.textContent = data[attr].aboutus;
                newsEl.textContent = data[attr].news;
                resultsEl.textContent = data[attr].results;
                leaguesEl.textContent = data[attr].leagues;
                loginEl.textContent = data[attr].login;
            });
        });
var data = {
    "english": 
    {
    "aboutus":"About Us",
    "news":"News",
    "results":"Results",
    "leagues":"Leagues",
     "login":"Profile",
      "headings": "News",
      "description": 
          "Last weekend there were a lot of great games."
    },
    "latvian": 
    {
        "Aboutus":"Par mums",
         "news":"Jaunumi",
        "results":"Rezultāti",
        "leagues":"līgas",
        "login":"profils",
        "headings": "Jaunumi",
         "description": 
            "Pagājušajā nedēļā bija ļoti daudz labu spēļu"
    }
  }</script>

Leetcode: Maximum Points You Can Obtain from Cards (Javascript)

Why is my solution wrong?!

QS Description:

There are several cards arranged in a row, and each card has an associated number of points. The points are given in the integer array cardPoints.

In one step, you can take one card from the beginning or from the end of the row. You have to take exactly k cards.

Your score is the sum of the points of the cards you have taken.

Given the integer array cardPoints and the integer k, return the maximum score you can obtain.

Example:

Input: cardPoints = [1,2,3,4,5,6,1], k = 3
Output: 12
Explanation: After the first step, your score will always be 1. However, choosing the rightmost card first will maximize your total score. The optimal strategy is to take the three cards on the right, giving a final score of 1 + 6 + 5 = 12.

MY SOLUTION

const maxScore = function (cardPoints: number[], k: number) {
  if (k > cardPoints.length || k < 1 || cardPoints.length < 1 || cardPoints.length > 10 ** 5) {
    console.log("see constrains again");
    return;
  }
  for (let i = 0; i < cardPoints.length; i++) {
    if (cardPoints[i] > 10 ** 4) {
      console.log("one of array members is higher than 10**4");
      return;
    }
  }


  let arr: number[] = [];
  let end = cardPoints.length - 1;
  let start = 0;

  for (let x = 0; x < k; x++) {
    arr.push(Math.max(cardPoints[start], cardPoints[end]));
    start++;
    end--;
  }
  
  return arr.reduce((a, b)=> a+b, 0);
};

When I click Run Code it is accepted as shown in this img
Run Code

When I click Submit it is wrong as shown in this img Submit code

HOw is it wrong answer ??! =>> 1+200+80

HTML – JS ; Youtube API V3 | How do I use two parts?

I’m currently working on a youtube clone and I want to show the videos on the start. And now i want to show the title, description and duration. I managed to show the title and thumbnail but now I don’t know how to insert the duration because the duration is not in the “snippet” part but in the “contentDetails” part. How can I use two parts at the same time? Below this is what I:ve done so far:

const videoCardContainer = document.querySelector('.video-container');
        let api_key = "##";
        let video_http = "https://www.googleapis.com/youtube/v3/videos?";
        let channel_http = "https://www.googleapis.com/youtube/v3/channels?"
        fetch(video_http + new URLSearchParams({
            key: api_key,
            part: 'snippet',
            chart: 'mostPopular',
            maxResult: 12,
            regionCode: 'DE'
        }))
        .then(res => res.json())
        .then(data => {
            //console.log(data);
            data.items.forEach(item => {
                getChannelIcon(item)
            })
        })
        .catch(err => console.Log(err));

        const getChannelIcon = (video_data) => {
            fetch(channel_http + new URLSearchParams({
                key: api_key,
                part: 'snippet',
                id: video_data.snippet.channelId
            }))
            .then(res => res.json())
            .then(data => {
                makeVideoCard(video_data);
            })
        }
        const makeVideoCard = (data) => {
            videoCardContainer.innerHTML += `
            <div class="info">
                        <h4 class="title">${data.snippet.title}</h4>
                        <p class="duration">${data.contentDetails.duration}</p>
                    </div>
            <div class="video">
                <img src="${data.snippet.thumbnails.high.url}" class="thumbnail" alt="">
                <div class="content">
                </div>
            </div>
            <style>
                .thumbnail
                {
                    width: 100px;
                }
                h4
                {
                    font-family: Arial, Helvetica, sans-serif;
                    font-size: 12px;
                    position: relative;
                    top: 30px;
                    left: 120px;
                }
            </style>
            `
        }

Does anyone know how I can use the “contentDetails” part too?
Thanks for your help 🙂