本文に 62 文字追加
ソース リンク

以前同じ目的で調べたことがあり、標準では用意されていないと知り、
実装したことがあります。

手元にあったそのコード(TypeScript)をJavaScriptに書き直しました。
いま環境がないので動作は未確認です。(上手く動いたら良いのですが)

アプローチとしては
まずディレクトリ内に含まれる全ファイルを列挙した後で、拡張子で絞る感じです。

import fs from 'fs';
import path from 'path';

const enumFilePaths = (dirPath, extension) => {
    const filePaths = [];

    const founds = fs.readdirSync(dirPath);
    founds.each((found) => {
        const subPath = path.resolve(dirPath, found);
        const stat = fs.statSync(subPath);
        if (stat.isFile()) {
            filePaths.push(subPath);
        }
    });

    const filtered = filePaths.filter((filePath) => {
        const ext = path.extname(filePath).toLowerCase().replace('.', '');
        return ext === extension;
    });

    return filtered;
};

const jsonFilePaths = enumFilePaths('./sample', 'json');

この jsonFilePaths をループで回して、$.getJSON() されると良いです。

少し改造すると、探す拡張子を2つ以上に増やしたり、 
サブディレクトリ内も探すようにもできます。
(元々その機能もありましたが、あなたの要件とは異なるのでペーストの際に省略しました)

以前同じ目的で調べたことがあり、標準では用意されていないと知り、
実装したことがあります。

手元にあったそのコード(TypeScript)をJavaScriptに書き直しました。
いま環境がないので動作は未確認です。(上手く動いたら良いのですが)

アプローチとしては
まずディレクトリ内に含まれる全ファイルを列挙し、拡張子で絞る感じです。

import fs from 'fs';
import path from 'path';

const enumFilePaths = (dirPath, extension) => {
    const filePaths = [];

    const founds = fs.readdirSync(dirPath);
    founds.each((found) => {
        const subPath = path.resolve(dirPath, found);
        const stat = fs.statSync(subPath);
        if (stat.isFile()) {
            filePaths.push(subPath);
        }
    });

    const filtered = filePaths.filter((filePath) => {
        const ext = path.extname(filePath).toLowerCase().replace('.', '');
        return ext === extension;
    });

    return filtered;
};

const jsonFilePaths = enumFilePaths('./sample', 'json');

この jsonFilePaths をループで回して、$.getJSON() されると良いです。

少し改造すると、探す拡張子を2つ以上に増やしたり、サブディレクトリ内も探すようにもできます。

以前同じ目的で調べたことがあり、標準では用意されていないと知り、
実装したことがあります。

手元にあったそのコード(TypeScript)をJavaScriptに書き直しました。
いま環境がないので動作は未確認です。(上手く動いたら良いのですが)

アプローチとしては
まずディレクトリ内に含まれる全ファイルを列挙した後で、拡張子で絞る感じです。

import fs from 'fs';
import path from 'path';

const enumFilePaths = (dirPath, extension) => {
    const filePaths = [];

    const founds = fs.readdirSync(dirPath);
    founds.each((found) => {
        const subPath = path.resolve(dirPath, found);
        const stat = fs.statSync(subPath);
        if (stat.isFile()) {
            filePaths.push(subPath);
        }
    });

    const filtered = filePaths.filter((filePath) => {
        const ext = path.extname(filePath).toLowerCase().replace('.', '');
        return ext === extension;
    });

    return filtered;
};

const jsonFilePaths = enumFilePaths('./sample', 'json');

この jsonFilePaths をループで回して、$.getJSON() されると良いです。

少し改造すると、探す拡張子を2つ以上に増やしたり、 
サブディレクトリ内も探すようにもできます。
(元々その機能もありましたが、あなたの要件とは異なるのでペーストの際に省略しました)

本文に 62 文字追加
ソース リンク

以前同じ目的で調べたことがあり、標準では用意されていないと知り、
実装したことがあります。

手元にあったTypeScriptのそのコード(TypeScript)をJavaScriptに書き直しました。
いま環境がないので動作は未確認です。(上手く動いたら良いのですが)

アプローチとしては
まずディレクトリ内に含まれる全ファイルを列挙し、拡張子で絞る感じです。

import fs from 'fs';
import path from 'path';

const enumFilePaths = (dirPath, extension) => {
    const filePaths = [];

    const founds = fs.readdirSync(dirPath);
    founds.each((found) => {
        const subPath = path.resolve(dirPath, found);
        const stat = fs.statSync(subPath);
        if (stat.isFile()) {
            filePaths.push(subPath);
        }
    });

    const filtered = filePaths.filter((filePath) => {
        const ext = path.extname(filePath).toLowerCase().replace('.', '');
        return ext === extension;
    });

    return filtered;
};

const jsonFilePaths = enumFilePaths('./sample', 'json');

この jsonFilePaths をループで回して、
 $.getJSON() されると良いです

少し改造すると、探す拡張子を2つ以上に増やしたり、サブディレクトリ内も探すようにもできます

手元にあったTypeScriptのコードをJavaScriptに書き直しました。
動作は未確認です。(上手く動いたら良いのですが)

アプローチとしては
まずディレクトリ内に含まれる全ファイルを列挙し、拡張子で絞る感じです。

import fs from 'fs';
import path from 'path';

const enumFilePaths = (dirPath, extension) => {
    const filePaths = [];

    const founds = fs.readdirSync(dirPath);
    founds.each((found) => {
        const subPath = path.resolve(dirPath, found);
        const stat = fs.statSync(subPath);
        if (stat.isFile()) {
            filePaths.push(subPath);
        }
    });

    const filtered = filePaths.filter((filePath) => {
        const ext = path.extname(filePath).toLowerCase().replace('.', '');
        return ext === extension;
    });

    return filtered;
};

const jsonFilePaths = enumFilePaths('./sample', 'json');

この jsonFilePaths をループで回して、
 $.getJSON() されると良いです。

以前同じ目的で調べたことがあり、標準では用意されていないと知り、
実装したことがあります。

手元にあったそのコード(TypeScript)をJavaScriptに書き直しました。
いま環境がないので動作は未確認です。(上手く動いたら良いのですが)

アプローチとしては
まずディレクトリ内に含まれる全ファイルを列挙し、拡張子で絞る感じです。

import fs from 'fs';
import path from 'path';

const enumFilePaths = (dirPath, extension) => {
    const filePaths = [];

    const founds = fs.readdirSync(dirPath);
    founds.each((found) => {
        const subPath = path.resolve(dirPath, found);
        const stat = fs.statSync(subPath);
        if (stat.isFile()) {
            filePaths.push(subPath);
        }
    });

    const filtered = filePaths.filter((filePath) => {
        const ext = path.extname(filePath).toLowerCase().replace('.', '');
        return ext === extension;
    });

    return filtered;
};

const jsonFilePaths = enumFilePaths('./sample', 'json');

この jsonFilePaths をループで回して、$.getJSON() されると良いです

少し改造すると、探す拡張子を2つ以上に増やしたり、サブディレクトリ内も探すようにもできます

ソース リンク

手元にあったTypeScriptのコードをJavaScriptに書き直しました。
動作は未確認です。(上手く動いたら良いのですが)

アプローチとしては
まずディレクトリ内に含まれる全ファイルを列挙し、拡張子で絞る感じです。

import fs from 'fs';
import path from 'path';

const enumFilePaths = (dirPath, extension) => {
    const filePaths = [];

    const founds = fs.readdirSync(dirPath);
    founds.each((found) => {
        const subPath = path.resolve(dirPath, found);
        const stat = fs.statSync(subPath);
        if (stat.isFile()) {
            filePaths.push(subPath);
        }
    });

    const filtered = filePaths.filter((filePath) => {
        const ext = path.extname(filePath).toLowerCase().replace('.', '');
        return ext === extension;
    });

    return filtered;
};

const jsonFilePaths = enumFilePaths('./sample', 'json');

この jsonFilePaths をループで回して、
$.getJSON() されると良いです。